Hi all,
I am encountering a strange problem with the DataSet Row.RejectChanges().
I'm populating a grid from a DataSet. The idea is that if the user
checks a cell the row in the dataset is updated. If the user unchecks
the row the row update is undone (row.rejectchanges) in the dataset.
My problem is as follows:
1. 5 Items in Grid...Check all 5. RowState = Modified
2. Uncheck 3 of these 5 items. RowState = Unchanged for 3 items and
Modified for 2 items. (As expected).
3. Call sqlAdapter.Update(tableIems). 4 Items have their RowState
set to Modified, not 3 items. If I check the DataSet one of the
items which originally had it's RowState = Unchanged now has
RowState = Modified.
My understanding is that Row.RejectChanges() will reject the changes to
that row since the last time AcceptChanges() was called. In this case
AcceptChanges() is called for sqlAdapter.Update() and at not time before
this.
Here is a editied snippet of my code ...
if (this.gridProducts[cell.RowNumber,cell.ColumnNumber].ToString() == CHECKED)
this.MarkItemAsChecked();
else
this.MarkItemAsUnChecked();
protected void MarkItemAsChecked()
{
DataRow row = (this.gridProducts.DataSource as DataTable).Rows.Find(ID);
row.BeginEdit();
row[0] = "SomeValue";
row.EndEdit();
}
protected void MarkItemAsUnChecked()
{
DataRow row = (this.gridProducts.DataSource as DataTable).Rows.Find(ID);
row.RejectChanges();
}
|