User (Old forums)MemberApril 3, 2009 at 5:52 amPost count: 23064
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.
Imported from legacy forums. Posted by bogdip (had 3727 views)User (Old forums)MemberApril 3, 2009 at 2:32 pmPost count: 23064User (Old forums)MemberApril 15, 2009 at 2:53 amPost count: 23064
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)? 🙂
Imported from legacy forums. Posted by bogdip (had 558 views)User (Old forums)MemberApril 15, 2009 at 3:23 pmPost 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)
- You must be logged in to reply to this topic.