Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
705
make delete in grid update underlying data source
posted

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();
                 }
            }

 

 

  • 37774
    Verified Answer
    posted

    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