[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
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
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.
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!
Re: [2.0] Saving changes to a datagridview - colour the rows
Quote:
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;