Home Forums WinForms controls Xceed Grid for WinForms NullReferenceException on deletion

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #13908 |

    Hey,

    I’ve been having a recurring issue with rows that, when you try and remove them, give you a NullReferenceException. My logic for removing the currently selected rows looks like this:

    while (myGrid.SelectedRows.Count > 0)
    {
    DataRow rootRow = GetRoot(myGrid.SelectedRows[0]);
    rootRow.Remove();
    }

    Where GetRoot looks like:
    private void GetRoot(DataRow row)
    {
    while (row.ParentGrid != null && row.ParentGrid.ParentDataRow != null)
    {
    row = row.ParentGrid.ParentDataRow;
    }

    return row;
    }

    The exception occurs on the rootRow.Remove(); line, but I can’t find anything odd in the debugger. rootRow is certainly _not_ null, and nor does it seem to have any properties which I assume to be critical to be null, such as the value of the primary key cell. This one is really making me pull my hair =(

    If it’s to any help, this only seems to happen on “root” rows, not any other rows.

    Imported from legacy forums. Posted by macke (had 2233 views)

    User (Old forums)
    Member
    Post count: 23064

    I forgot that I also to myGrid.BeginInit() before the loop and myGrid.EndInit() afterwards.

    Imported from legacy forums. Posted by macke (had 191 views)

    User (Old forums)
    Member
    Post count: 23064

    My problem seems to have gone away by first releasing the databindings before some dataset operation and then updating them again. I have really little idea of what’s going on, but it seems to work now.

    Imported from legacy forums. Posted by macke (had 3343 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.