We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

System.NullReferenceException when binding to childData on GroupExpanding Event

Hi We get a NullReferenceException when we populate our related grid''s datasource on the GroupExpanding event. The resulting grid looks fine, but it doesn''t add a new row and it is extremely slow because of the Exception that gets raised and caught internally. Here is a brief description of what we do: 1) We bind all possible child tables to a dataSource that contains only the structure of the related tables. 2) We setup the Parent-Child relationships manually using the GridRelationDescriptor. 3) We add event listener to the GroupExpanding event. 4) When the event is raised we Retrieve the data that must be in the related Grid using the current recordID. 5) We set the SourceListSetEntry for the child table to the newly populated DataSource using the following code: SourceListSetEntry sourceEntry = base.Engine.SourceListSet [RELATED_CLASS_NAME]; sourceEntry.List = (ClientView) v ; We can step through our code but once we exits the GroupExpanding event handler we get the following output in our output window: System.NullReferenceException: Object reference not set to an instance of an object. at Syncfusion.Grouping.ChildTable.get_ParentNestedTable() at Syncfusion.Grouping.ChildTable.get_ParentDisplayElement() at Syncfusion.Grouping.Element.GetVisibleInHierarchy() at Syncfusion.Grouping.Table.RaiseGroupExpanding(Group group, Boolean raiseDisplayElementChangeEvents) at Syncfusion.Grouping.Group.SetExpanded(Boolean value, Boolean refreshCounters, Boolean raiseDisplayElementChangeEvents) at Syncfusion.Grouping.Group.set_IsExpanded(Boolean value) at Syncfusion.Grouping.NestedTable.set_IsExpanded(Boolean value) at Syncfusion.Grouping.CurrentRecordManager.NavigateTo(Element record, Boolean cancelEditIfNotValid, Boolean scrollInView) at Syncfusion.Windows.Forms.Grid.Grouping.GridTableControl.OnCellButtonClicked(GridCellButtonClickedEventArgs e) at Syncfusion.Windows.Forms.Grid.GridControlBase.RaiseCellButtonClicked(Int32 rowIndex, Int32 colIndex, Int32 index, GridCellButton button) catched at Syncfusion.Windows.Forms.Grid.GridControlBase.RaiseCellButtonClicked(Int32 rowIndex, Int32 colIndex, Int32 index, GridCellButton button) in :line 0 Can you please give me an idea of why this happens and How we can get past it? Unfortunately I cant send you a code snippet that mimics this - it is part of a much bigger project. Regards. TD

5 Replies

AD Administrator Syncfusion Team July 19, 2005 07:12 PM UTC

Hi Theo, this is the code for ChildTable.ParentNestedTable: public NestedTable ParentNestedTable { get { Table relationParentTable = this.ParentTable.RelationParentTable; if (relationParentTable != null) { if (nestedTableEntry == null) { relationParentTable.EnsureInitialized(this, false); relationParentTable.GetVisibleCount(); // will trigger updating records thus establishing a link to // this nested table when the records AdjustRecordRowCount is hit. NestedTableEntry should be //// set for this object! } } return nestedTableEntry != null ? nestedTableEntry.Element : null; } } Looking at the code I am pretty sure the null reference exception occurs when ParentTable returns null and then the code goes on to check ParentTable.RelationParentTable The reason why ParentTable is null is either: a) The object is stand-alone and has no parent relation ship to other elements. or b) The object has been disposed. I guess that b) is the case. When you replace the SourceListSet the datasource for the nested tables changes and that might trigger the old datasource to be disposed. But I am more or less guessing here. What kind of relationship do you have? Is it a UniformChildList or is it RelatedMasterDetails? If it is a UniformChildList there should be no need to replace the datasource in SourceListSet. If it is a RelatedMasterDetails then instead of replacing the datasource in SourceListSet try instead to start of with a emply list registered in SourceListSet and then at the time of the GroupExpanding event go through the list of records you want to show and then add them to that table that is registered in SourceListSet. Stefan >Hi > >We get a NullReferenceException when we populate our related grid''s datasource on the GroupExpanding event. The resulting grid looks fine, but it doesn''t add a new row and it is extremely slow because of the Exception that gets raised and caught internally. > >Here is a brief description of what we do: >1) We bind all possible child tables to a dataSource that contains only the structure of the related tables. > >2) We setup the Parent-Child relationships manually using the GridRelationDescriptor. > >3) We add event listener to the GroupExpanding event. > >4) When the event is raised we Retrieve the data that must be in the related Grid using the current recordID. > >5) We set the SourceListSetEntry for the child table to the newly populated DataSource using the following code: >SourceListSetEntry sourceEntry = base.Engine.SourceListSet [RELATED_CLASS_NAME]; > sourceEntry.List = (ClientView) v ; > >We can step through our code but once we exits the GroupExpanding event handler we get the following output in our output window: > >System.NullReferenceException: Object reference not set to an instance of an object. > > at Syncfusion.Grouping.ChildTable.get_ParentNestedTable() > > at Syncfusion.Grouping.ChildTable.get_ParentDisplayElement() > > at Syncfusion.Grouping.Element.GetVisibleInHierarchy() > > at Syncfusion.Grouping.Table.RaiseGroupExpanding(Group group, Boolean raiseDisplayElementChangeEvents) > > at Syncfusion.Grouping.Group.SetExpanded(Boolean value, Boolean refreshCounters, Boolean raiseDisplayElementChangeEvents) > > at Syncfusion.Grouping.Group.set_IsExpanded(Boolean value) > > at Syncfusion.Grouping.NestedTable.set_IsExpanded(Boolean value) > > at Syncfusion.Grouping.CurrentRecordManager.NavigateTo(Element record, Boolean cancelEditIfNotValid, Boolean scrollInView) > > at Syncfusion.Windows.Forms.Grid.Grouping.GridTableControl.OnCellButtonClicked(GridCellButtonClickedEventArgs e) > > at Syncfusion.Windows.Forms.Grid.GridControlBase.RaiseCellButtonClicked(Int32 rowIndex, Int32 colIndex, Int32 index, GridCellButton button) > >catched at Syncfusion.Windows.Forms.Grid.GridControlBase.RaiseCellButtonClicked(Int32 rowIndex, Int32 colIndex, Int32 index, GridCellButton button) in :line 0 > > >Can you please give me an idea of why this happens and How we can get past it? Unfortunately I cant send you a code snippet that mimics this - it is part of a much bigger project. > >Regards. >TD >


TD Theo Danzfuss July 20, 2005 10:16 AM UTC

Ok, I have tried this. Still no Joy I dont bind to a DataTable, I bind to a Custom collection that fully implements IBindingList and ITypedList I now bind to an empty ClientView at initial startup. Then in the the GroupExpanding event I "Merge" my new results into the sourceEntry.List Reference, which is a clientview(Custome collection). When inspecting the Count of the sourceEntry.List before and After the merge I can verify that the sourceEntry.List does contain the new data, but the datagrid only shows an Empty related grid. Here is the Code snippet that Merges my new data: ClientView.Merge ( v ,( ClientView ) sourceEntry.List ) ; Maybe there is something in my Custom Collection that doesn''t function correctly? I have confirmed that the Collection implement the SupportsChangeNotification, ListChanged and OnListChanged methods. The Exception is gone now, but as I said, I don''t see any data in the related grids although they are in the collection - Do you have any ideas? Regards, TD


AD Administrator Syncfusion Team July 20, 2005 12:38 PM UTC

Hi Theo, I think the grid is simply not aware of the new records. You could try and set Table.TableDirty = true for the related table that corresponds to the list where you inserted the records. Or you should try to implement IBindingList or IListChangedSource, most important the ListChanged event. IListChangedSource is a stripped down version of IBindingList. The interface only has the ListChanged event to notify the engine about changes in a bound datasource. So that might be ideal for you. Stefan >Ok, I have tried this. Still no Joy > >I dont bind to a DataTable, I bind to a Custom collection that fully implements >IBindingList and ITypedList > >I now bind to an empty ClientView at initial startup. Then in the the GroupExpanding event I "Merge" my new results into the sourceEntry.List Reference, which is a clientview(Custome collection). When inspecting the Count of the sourceEntry.List before and After the merge I can verify that the sourceEntry.List does contain the new data, but the datagrid only shows an Empty related grid. Here is the Code snippet that Merges my new data: > >ClientView.Merge ( v ,( ClientView ) sourceEntry.List ) ; > >Maybe there is something in my Custom Collection that doesn''t function correctly? I have confirmed that the Collection implement the SupportsChangeNotification, ListChanged and OnListChanged methods. > >The Exception is gone now, but as I said, I don''t see any data in the related grids although they are in the collection - Do you have any ideas? > >Regards, >TD >


TD Theo Danzfuss July 21, 2005 08:06 AM UTC

Hi, Yes it looks as if my ListChanged Event doesnt fire correctly - I tried to hook-up my own handler without success. Will the Grid refresh correctly if I set the Table.TableDirty property even if the ListChanged event doesn''t fire? Thanx TD


AD Administrator Syncfusion Team July 21, 2005 11:40 AM UTC

Yes, it will reload the whole table (the list where you merged in those records from the other tables ...) and recategorize everything. It might be a bit slow when you have more records in that table. Stefan >Hi, > >Yes it looks as if my ListChanged Event doesnt fire correctly - I tried to hook-up my own handler without success. >Will the Grid refresh correctly if I set the Table.TableDirty property even if the ListChanged event doesn''t fire? > >Thanx >TD

Loader.
Live Chat Icon For mobile
Up arrow icon