I have some sort of undo functionality in my application. I remove a row from the GUI an could undo or commit it through the underlaying DataTable-functions RejectChanges or AcceptChanges. But when I try to remove the row and undo it via the RejectChanges-functions it does not work, because GetChanges copies the table with its rows and is not returning the acutal DataRow from the original DataTable. Is there a possibility to access the original row through the DataTable returned by GetChanges()? I need to only reject some rows by the DataRow.RejectChanges()-function, so I cannot use DataTable.RejectChanges(). The only thing I found is the Find()-function via the tables primary key. Is there another possibility?
EDIT: I tried the Find()-function and it would not work either, because using the original value from the undo-row cannot find the row in the original table, because this row is marked as deleted.
DataTable originalTable = GetTable();
DataTable del = originalTable.GetChanges(DataRowState.Deleted);
if (del != null)
{
foreach (DataRow r in del.Rows)
{
r.RejectChanges(); // not working, bc its the row of 'del'
DataRow orig = originalTable.Rows.Find(r["id", DataRowVersion.Original]); // not found, because in the current version of originalTable it is not existing
orig?.RejectChanges();
}
}
need to only reject some rowswhy? That's what blocks you. In any case, thexxxChangesmethods are intended to implement transaction semantics, not versioning. Row Versions are used to return the original, current or proposed values of a row and are intended for optimistic concurrency.GetChangesdocs shows how to get the pending changes and persist them, only committing changes to the grid after a successful save.