Home Forums WinForms controls Xceed Grid for WinForms Removing a DataRow from a Grid throws a "Object reference not set to an instance of an object." exception.

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

    Hello,
     
    I’m comming back with a new issue:
     
    I have to remove a DataRow from a Xceed.Grid.GridControl. But a “NullReferenceException” is thrown and I don’t understand why. It gave me hard headakes last hours. Maybe I’m missing somethiong from my view …

    This is my code:

                    List<DataRow> rowToRemoveList = _myGrid.GetRows(removedProperty, false);//get all rows which contains this property

                    for (int i = 0; i < rowToRemoveList.Count; i++)
                        _myGrid.DataRows.Remove(rowToRemoveList[ i ]);

    The stack trace of the exception is as follows:

       at Xceed.Grid.DataRow.IsParentOf(Row row)
       at Xceed.Grid.Collections.DataRowList.OnRemoveComplete(Int32 index, Object value)
       at Xceed.Utils.Collections.ListBase.InternalRemoveAt(Int32 index)
       at Xceed.Utils.Collections.ListBase.ListRemove(Object value)
       at Xceed.Grid.Collections.DataRowList.Remove(DataRow value)
       at MyApp.UIBuilders.ProjectionTabPaneBuilder.FormQuery_UIAction(Object o, UIEventArgs args) in G:\MyApp\UIBuilders\ProjectionTabPaneBuilder.cs:line 159
       at MyApp.UI.FormQuery.UIEventHandler.Invoke(Object o, UIEventArgs args)
       at MyApp.UI.FormQuery.OnUIAction(Object uiObject, UIEventArgs args) in G:\MyApp\FormQuery.cs:line 202
       at MyApp.UIBuilders.DiagramBuilder.DeleteProperty(Property property) in G:\MyApp\UIBuilders\DiagramBuilder.cs:line 223

    I must specify the followings:

    1. The rows to be deleted can have one detail grid with one or more rows(sub rows) which also can have sub rows, etc. Like a tree structure.

    2. The rows to be deleted are main rows (their ParentGrid is a MasterGrid) not sub-rows.

    3. The current row to be deleted (when the exception is fired) is not null and it is contained in the _myGrid.DataRows. (tested in Watch window of VS)

            a) _myGrid.DataRows.Contains(rowToRemoveList[ i ])  evaluates to TRUE

            b) rowToRemoveList[ i ].GridControl == _myGrid evaluates also to TRUE

    4. The row seems though to be deleted (although the exception is thrown), because the grid’s DataRows count is decreased by 1 and the row is not anymore contained in the grid rows list.

    5. I noticed that if I change the order the rows are deleted (say same rows, same grid, but different order of deletion) the exception is not anymore thrown.

    I ran out of ideas of what should I do to it to work. Even if the row seems to be deleted I don’t like to catch that exception and do nothing, I’m not sure
    the grid state is not corrupted after the deletion.

    Please help me understand why tha call to “Xceed.Grid.DataRow.IsParentOf(Row row)” throws a “NullReferenceException” and what shoul I do to avoid that.

    Thanks,
    Bogdan

    Imported from legacy forums. Posted by bogdip (had 3727 views)

    User (Old forums)
    Member
    Post count: 23064

    We do not reproduce the exception here.  We’re actually a bit puzzled by this.  Could you send a sample application reproducing the issue to support@xceed.com, with a link to this post, so we can investigate this further?

    Imported from legacy forums. Posted by André (had 2140 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello,

     

    Finally I found the problem. It turned out that somewhere after deleting the row, in a “RefreshUI” method, I was setting the grid.CurrentRow to null (don’t ask me why, I think I made a confusion to GridControl.SelectedRows or such) but this assignment is not allowed by the GridControl framework. Maybe if an exception will be thrown when trying to assign null to CurrentRow will make the programmer life easier (less error-prone)? 🙂

     

    Bogdan

    Imported from legacy forums. Posted by bogdip (had 558 views)

    User (Old forums)
    Member
    Post count: 23064

    The CurrentRow property on the GridControl CAN be set to null, so your issue is likely due to something else.  We would need to see some code or have a sample application reproducing the issue to be able to tell what is causing this, unless you feel the issue is resolved to your satisfaction.

    Imported from legacy forums. Posted by André (had 2847 views)

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