Hi everybody!
I have the next code and I’m having a problem with the DataRow:
DataTable dt = new DataTable();
dt.Load(GetReader());
dataGridView.DataSource = dt;
DataRow[]originalRows = dt.Select();
The problem is that when I change a cell value in the datagridview the change is also set in the originalRows values. I’d like to avoid this, since I want to use the original values of the datatable to compare them later to see whether there ware changes in my datagridview.
I tried the following but it didn't work:
private void dataGridView_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
originalRows[e.RowIndex].CancelEdit();
originalRows[e.RowIndex].EndEdit();
}
Thanks in advance,
Elvia
PS: Windows application in Microsoft Visual C# 2005
Elvia GonzalezPosted May 5, 2006, 3:41 PM
Hi!
I was trying to solve the problem the wrong way. The Select method of the DataTable returns references to the rows in the table, not clones. When a value in a row is changed via the grid, the corresponding row in the table (and, hence, an element in my
originalRowsarray) will reflect that change.So I call Copy on the DataTable, instead of Select, to get a complete and separate copy of the entire table. Later, I compare each value in each row with the copied (unmodified) table to the one bound to the grid.
The problem is solved thanks to somebody else who helped me. I wanted to share this with you, so if you have the problem later.
Best Regards,
Elvia