|
This is a C# forum, not C.
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
Write your own code or take the FAMOUS PROGRAM IN THE WORLD :
Console.WriteLine("Hello World");
|
|
|
|
|
Hi,
I am deploying a c# database with which i am also deploying SQL express. I need to deploy database after installation as well. I have the .mdf file. I want to know how can i place the .mdf in the appropriate folder. ( And also which folder is apporpriate for this purpose).
Regards,
Wasif Ehsan.
|
|
|
|
|
This would be better in the SQL forum, but here you go... my company does this and distributes the .mdf file and then runs a SQL script to attach to the database. I think it is a better solution to build a SQL script for the database and have it create the tables, stored procedures, etc instead of distributing the .mdf file. But if you must, you can put the .mdf file anyplace on the drive and use the sp_attach_db stored procedure.
sp_attach_db @dbname = 'Pat',
@filename1 = 'C:\db\Pat.mdf',
@filename2 = 'C:\db\Pat_log.ldf'
Steve Maier, MCSD MCAD MCTS
|
|
|
|
|
Hi
Is it possible to show different image in one column in each row depending on status of other column in the grid?
For example:
stop o
running ~
waiting x
I wouldn't like to create my own class representing ImageCell. Just using CellPainting event.
I do like this in CellPainting:
e.Graphics.DrawImage(img, e.CellBounds);
img depends on value of another column (status)
...but it doesn't work. Image is drawn and disappears
Thanks
Ela
|
|
|
|
|
e_LA wrote: Image is drawn and disappears
It's hard to help you without seeing the context of the drawing code. If it's drawn but then disappears, either you're drawing code is wrong or you're drawing in the wrong place.
|
|
|
|
|
Ok
When I put only such a code in cellpainting event
private void myDataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex > -1 && e.RowIndex > -1)
{
Image img = global::MyApplication.Properties.Resources.GreenImage;
e.Graphics.DrawImage(img, e.CellBounds);
}
}
Anything is drawn. Why?
In fact it is drawn and dissapears - I checked it.
What is wrong?
|
|
|
|
|
Instead of setting up a CellPainting handler, define a DataGridViewCell type and override the Paint method, then put your painting code inside that overridden method.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
What is a difference between overriding the Paint method and setting up a CellPaining handler?
Can I define a DataGridViewCell type and add it to an existing column?
Thanks for help
Ela
|
|
|
|
|
Ok I defined my own class representing column and cell class where I overriden a Paint method.
In the Paint method I would like to draw image depending on value of another column.
I have to take DataSource (DataView) where I could check the value in another column in the same row (RowIndex).
That's why I created cell constructor like that
public ImageCell(DataGridView dGridV)
{
this.grid = dGridV;
}
When in Paint method I put such a line
DataView dv = (DataView)grid.DataSource;
I have an exception because grid is null.
I think during adding column to grid operation default constructor of the cell is called (which is empty in my case). Am I right?
Thanks
Ela
|
|
|
|
|
Yes, it works now. I have only message on Console window:
FormattedValueType property of a cell cannot be null.
I tried to override FormattedValueType property but it doesn't not works.
Another thing is sometimes I have to display animated gif in the cell.
However when I want to animate gif I have to call Invalidate method which does not exist for the cell.
Thanks
Ela
|
|
|
|
|
Hi All,
I have a problem combining results of two queries. The queries are fired on the same table with the same select list, only the where condition changes. It would be better if i show what i actually want.
This is my table data for example.
Field1 Field2
AB 1
SD 2
SDFG 3
AS 4
QWE 5
BBG 6
I want an output as
Field1 Field2
AS 4
QWE 5
BBG 6
AB 1
SD 2
That means , if i give the value for Field2 = 3 in the query then the result will not contain record with Field2 = 3 and the result should display the record with Field2 > 3
first and the with Field2 < 3 both sorted in ascending order.
I am using the union operator for combining results, but the results are not as desired. Also i feel that the union clause is not efficient since it takes about 4-6 secs to fetch the records.
Is there any efficient solution for my problem. Please reply soon as i have already spent considerable time on this query and i am running short of time now.
Any help will be appreciable.
Thanks in Advance.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
SELECT field1, field2
FROM table1
WHERE field2 > @someNumber
UNION
SELECT field1, field2
FROM table1
WHERE field2 <= @someNumber
The only problem is the order by clause is applied to the entire union at the end. So we need to cheat a little
SELECT field1, field2, 0 as ignoreMe
FROM table1
WHERE field2 > @someNumber
UNION
SELECT field1, field2, 1 as ignoreMe
FROM table1
WHERE field2 <= @someNumber
ORDER BY ignoreMe ASC, field1 ASC, field2 ASC
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Thanks Alot Ennis Ray Lynch, Jr. !
It worked fine.
But can u suggest something about, how can this query be optimized ?
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
The only optimization is to index field 2 and field 1. I don't know your server hardware but it is a simple query and should be instant on data sets less than 100,000 records. I just tested it on our oracle box and 6.5 million records takes 29 seconds.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
An interesting problem:
I have a ListView with LabelEdit set to TRUE. When I change the label, I want to make some decisions as to whether the ListViewItem (that's just been edited) should stay in the ListView or not.
The natural place to inspect this is in the AfterLabelEdit event...
If the decision is to take the item out, I used the ListViewItem.Remove().
However - check this out:
A) say that the item's index is N (indices are zero-based)
B) if there exists an item after it (i.e. with index N+1)
then this item gets quietly removed
C) if the item is the last in the list,an exception is thrown
saying that index N (requested to be removed) is non-existant.
It looks like:
D) when the item is being edited, it is taken OUT of the
ListView.Items collection. So - the original item N+1 moves up and
is temporarily assigned index N (that is how it gets removed - see
B) above)
E) if however, item N is the last in the collection and gets
temporarily taken out while being edited, then of course we get
and exception thrown as there isn't an item with index N
This can easily be proved:
1. create a new Windows Forms project
2. add a ListView to the form
3. Set LabelEdit to TRUE
4. Add 3 items to the list, with labels e.g. 'Item1', 'Item2' and 'Item3'
5. Create a handler for the AfterLabelEdit event
6. Inside this handler add this code:
ListViewItem item = listView1.Items[e.Item];
item.Remove();
7. Run the application
8. Edit the first item and press Enter -> the second item is removed
9. Next, edit the last item then press Enter -> exception is thrown
This is all very nice...
But - can someone suggest an elegant workaround , i.e. - where and
how can I remove items after they have been edited?
Many thanks in advance.
alekyork
|
|
|
|
|
What you are trying to do will work if you set e.CancelEdit = true befor removing the the item: in the AfterEdit handler:
e.CancelEdit = true;
listVew1.Items[e.Item].Remove();
We need to graduate from the ridiculous notion that greed is some kind of elixir for capitalism - it's the downfall of capitalism. Self-interest, maybe, but self-interest run amok does not serve anyone. The core value of conscious capitalism is enlightened self-interest.
Patricia Aburdene
|
|
|
|
|
We have a DataGridView which is bound to a dataset and has a DataGridViewCheckBox cell that is used to select a row. It is done this way because the user must select which rows of data will be released to the next stage of processing.
The DataGridViewCheckBox (naturally) is not bound.
I have an event handler that is trapping the ClickEvent on the box as follows:
private void HandleCheckedEvent(object sender, DataGridViewCellEventArgs e)
{
if ( !m_formLoaded ) return;
else if ( m_functionCode != "E01" ) return;
else if ( e.ColumnIndex != 0 ) return;
DataGridViewCheckBoxCell currentCell = ( ( DataGridView )sender ).Rows[ e.RowIndex ].Cells[ e.ColumnIndex ] as DataGridViewCheckBoxCell;
if ( currentCell == null )
return;
else
DetermineButtonState( (DataGridView)sender, currentCell, e.RowIndex );
}
Right now the DetermineButtonState method just throws up a MessageBox showing me the state of the currentCell. When I run the code the Value of the cell is ALWAYS NULL! How can I properly manage if someone checks or unchecks a box at the time it happens???? According to MSDN the click event sends me the event just before the value is set so it seems that the first click being null should be fine. The second (uncheck) event, though, should be showing a currentCell.Value of True and the next (check) event should show me a currentCell.Value of False. Why is it NULL???? How do I get around this???? Is it okay to kill the developer that wrote this control???
Thanks for any help.
|
|
|
|
|
Is currentCell null because it is not of type DataGridViewCheckBoxCell? Or is it null because ...Cells[e.ColumnIndex] is actually null?
|
|
|
|
|
The currentCell.Value was null because it was not persisting the value.
After digging into things I was going to write my own control that would guarantee the state is maintained. Then when I went to see what existed for Notes to Inheriters I found code that showed what I had to do.
It turns out that I cannot check the state of the checkbox with only a single event. I have to do it in two events.
First binding to the datagridview.CurrentCellDirtyStateChanged and force the control to persist the data with cell.CommitEdit. That indirectly forces the datagridview.CellValueChanged event which now allows me to investigate the cell state value.
I now have everything working as expected !!!
|
|
|
|
|
Hi.
Does anybody know if it is possible to write programatically a text in a web application page with functionnalities like "newline", "tab", "center text",...
In fact: organise a text programatically before putting it in a web page.
Thanks,
Oren
|
|
|
|
|
You can write text and format it with normal html controls. Then u can add this to one of the block-level element( , etc).
Example:
1. Type the following script in notepad and save it in wwwroot folder with name such as "Test1.aspx"
2. Open Internet Explorer and the type URL: http://localhost/Test1.aspx
<script runat="server">
Sub Page_Load(sender As Object,e As EventArgs)
Dim str As String="<h1><center> Welcome To Web<b/> Appplication </center></h1> in <br /> <h3>ASP.NET</h3>"
div1.InnerHtml=str
End Sub
</script>
<html>
<head>
</head>
<body>
A Simple Test<br />
<form runat="server">
<p id="div1" runat="server" />
</form>
</body>
</html>
I dont know wheather may reply solve ur problem. However i just tried.
|
|
|
|
|
You can write text and format it with normal html controls. Then u can add this to one of the block-level element( , etc).
Example:
1. Type the following script in notepad and save it in wwwroot folder with name such as "Test1.aspx"
2. Open Internet Explorer and the type URL: http://localhost/Test1.aspx
<script runat="server">
Sub Page_Load(sender As Object,e As EventArgs)
Dim str As String="<pre><h1><center> Welcome To Web<b/> Appplication </center></h1> in <br /> <h3>ASP.NET</h3> "
div1.InnerHtml=str
End Sub
A Simple Test
|
|
|
|
|
You can write text and format it with normal html controls. Then u can add this to one of the block-level element( , etc).
Example:
1. Type the following script in notepad and save it in wwwroot folder with name such as "Test1.aspx"
2. Open Internet Explorer and the type URL: http://localhost/Test1.aspx
<script runat="server">
Sub Page_Load(sender As Object,e As EventArgs)
Dim str As String=<pre>"<h1><center> Welcome To Web<b/> Appplication </center></h1> in <br /> <h3>ASP.NET</h3>"
div1.InnerHtml=str
End Sub
A Simple Test
|
|
|
|
|
sorry for inconvience. The browser is parsing data section. The contents of str varaible are as under:
<h1><center> Welcome To Web<b/> Appplication </center></h1> in <br /> <h3>ASP.NET</h3>
|
|
|
|