|
-
Mar 27th, 2007, 04:39 PM
#1
Thread Starter
Frenzied Member
[2.0] Saving changes to a datagridview - colour the rows
Hello,
[VS 2005]
I am using typed datasets. I have 2 datagridView and when I click one GridA it will add a row to GridB. This works fine and the data is saved to the database.
However, the customer wants to add the rows to GridB and save periodically.
I am wondering is there a way to show the rows that have not been saved, and when the user clicks the save button it will change them to a different colour.
So it will commit some rows everytime the user clicks save. The user can add some more rows and they will be displayed in blue. Once the user clicks save all the rows that have just been added will be saved to the database and then change colour to green.
Can anyone point me in the right direction or give me some code example, will be most grateful.
Many thanks,
Steve
-
Mar 27th, 2007, 05:53 PM
#2
Re: [2.0] Saving changes to a datagridview - colour the rows
This is untested but it would be something like handling the CellValidated event and implementing the following:
vb Code:
Dim gridRow As DataGridViewRow = myGrid.Rows(e.RowIndex)
Dim tableRow As DataRow = DirectCast(gridRow.DataBoundItem, DataRowView).Row
If tableRow.RowState = DataRowState.Unchanged Then
gridRow.DefaultCellStyle.BackColor = Color.Green
Else
gridRow.DefaultCellStyle.BackColor = Color.Blue
End If
-
Mar 27th, 2007, 05:55 PM
#3
Re: [2.0] Saving changes to a datagridview - colour the rows
Bah! Forgot I was in C# land. You've posted in VB.NET so I'll assume that you can perform the conversion.
-
Aug 18th, 2007, 10:07 PM
#4
Fanatic Member
Re: [2.0] Saving changes to a datagridview - colour the rows
JM, I just want to ask if DirectCast method can be use in C#? is there anything i need to reference to? Thanks in advance!
-
Aug 18th, 2007, 10:46 PM
#5
Re: [2.0] Saving changes to a datagridview - colour the rows
 Originally Posted by daimous
JM, I just want to ask if DirectCast method can be use in C#? is there anything i need to reference to? Thanks in advance!
This:
vb.net Code:
Dim var As SomeType = DirectCast(obj, SomeType)
is equivalent to this:
C# Code:
SomeType var = (SomeType)obj;
This:
vb.net Code:
Dim var As SomeType = TryCast(obj, SomeType)
is equivalent to this:
C# Code:
SomeType var = obj as SomeType;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|