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
762
Re-adding a previously-deleted row not appearing in grid
posted

We have an Infragistics UltraGrid in a old WinForms application that is bound to a DataTable. Periodically new records are submitted to this table; either new data or changes to existing data. We can tell if this is an existing row by examining a 'batchID' column. We handle this by first deleting all rows of the DataTable with matching batchID, then adding the new row. Simplified:

for (int i = boundDataTable.Rows.Count - 1; i >= 0; i--)
{
    var r = (MyDataType)boundDataTable.Rows[i];
    if (r.batchID == incomingRow.batchID)
        r.Delete();
}
boundDataTable.ImportRow(incomingRow as DataRow);

If the incomingRow is a new record this works fine, but if it matches an existing batchID the existing records with the same batchID are removed (which is good) but the new data is not shown (which is bad). boundDataTable.ImportRow is called in both situations, but the new row is only shown in the grid if it was not previously there.

  • 469350
    Offline posted

    Hi,

    I can't see any obvious reason why this wouldn't work. What version of the grid are you using? From what event is this code called?

    My best guess is that the grid is getting delete notification at the same time it's processing an add notification and so this is causing some kind of timing problem. If you can encapsulate the code, you could try something like this:

    grid.BeginUpdate();

    grid.SuspendRowSyncrhonziation();

    try

    {

    // your code that adds and deletes rows in the DataTable here

    }

    finally

    {

    grid.ResumeRowSyncrhonziation();

    grid.EndUpdate();

    }

    This basically tells the grid not to process each individual change notification until they are all done. So if this is a timing issue, it should be alleviated. It also has the added benefit of making the code a little more efficient since the grid will only process one change instead of many.

    If that doesn't work, then another thing you could try is to force the grid to refresh after the operation has completed. Like so:

    grid.Rows.Refresh(ReloadData);

    If that still doesn't work, then maybe you could try to duplicate the problem in a small sample project and post it here so we can check it out.

  • 469350
    Offline posted

    One other thought... is it possible that the new row has already been added to the DataTable before this code fires and is therefore getting deleted immediately?