PDA

Click to See Complete Forum and Search --> : [2.0] Saving changes to a datagridview - colour the rows


steve_rm
Mar 27th, 2007, 04:39 PM
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

jmcilhinney
Mar 27th, 2007, 05:53 PM
This is untested but it would be something like handling the CellValidated event and implementing the following: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

jmcilhinney
Mar 27th, 2007, 05:55 PM
Bah! Forgot I was in C# land. You've posted in VB.NET so I'll assume that you can perform the conversion.

daimous
Aug 18th, 2007, 10:07 PM
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!

jmcilhinney
Aug 18th, 2007, 10:46 PM
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:Dim var As SomeType = DirectCast(obj, SomeType)is equivalent to this:SomeType var = (SomeType)obj;This:Dim var As SomeType = TryCast(obj, SomeType)is equivalent to this:SomeType var = obj as SomeType;