When I delete a grid using this C#:
ultraGridSelected.DeleteSelectedRows(false);
it deletes the row correctly. However, if I later in code try to reference the underlying datasource, I have to check the rowstate to see if that row is marked as deleted. Otherwise I get an error. I know there is an .AcceptChanges() method you can call on a datatable to reconcile this. How do I do this to make the grid do this so I no longer have to check the rowstate property?
DataTable GridSource = (DataTable)ultraGridSelected.DataSource;foreach (DataRow Row in GridSource.Rows) { if (Row.RowState.ToString().ToUpper() != "DELETED") { string myField = Row["myfield"].ToString(); } }
There isn't really anything in the grid to do this. The grid basically tells the DataSource that it should delete the row, and leave it at there; the grid will remove the UltraGridRow from its own collection on the next repaint. What you are experiencing is related to the implementation of the DataTable, which doesn't actually remove the row from its collection until you call AcceptChanges. If you always want to do this, you might be able to call AcceptChanges in the AfterRowsDeleted event of the grid.
-Matt