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)