Have a look at RowStateFilter. The following code displays unchanged, new,
modified and deleted rows.
DataView dataView = (DataView)((CurrencyManager)dataGrid1.BindingContext[
dataGrid1.DataSource, dataGrid1.DataMember ]).List;
dataView.RowStateFilter = System.Data.DataViewRowState.CurrentRows |
System.Data.DataViewRowState.Deleted;
Then I would use a custom DataGridTextBoxColumn class to colour the rows
depending on the RowState.
public class CustomDataGridTextColumn : DataGridTextBoxColumn
{
protected override void Paint(System.Drawing.Graphics g,
System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source,
int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush,
bool alignToRight)
{
Brush newForeBrush = null;
DataRow dataRow = ((DataView)source.List)[ rowNum ].Row;
switch (dataRow.RowState)
{
case DataRowState.Added:
newForeBrush = new SolidBrush(Color.Blue);
break;
case DataRowState.Deleted:
newForeBrush = new SolidBrush(Color.Red);
break;
case DataRowState.Modified:
newForeBrush = new SolidBrush(Color.Green);
break;
default:
break;
}
if (newForeBrush != null)
{
base.Paint(g, bounds, source, rowNum, backBrush, newForeBrush,
alignToRight);
newForeBrush.Dispose();
}
else
{
base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
}
}
}
Regards,
Phil.
Vladimir Kasal said:
Hello,
I use DataGrid that displays data from DataTable. When I delete a row, this
row disapears in DataGrid and changes it's status in DataTable.
I there any way how to display everything what's in DataTable?
I want that user will see all changes made and after clicking some "Commit"
button those changes will be saved into the database.
Thanks a lot
Vladimir