Completed
Last Updated: 04 Jul 2012 07:55 by Jesse Dyck
ADMIN
Julian Benkov
Created on: 04 Jul 2012 02:33
Category: TreeView
Type: Bug Report
1
NullReferenceException when adding new items to TreeView self-referencing datasource
Summary of the program logic:
The app allows the user to edit hierarchical data that is serialized/deserialized from an XML file. It is first deserialized into a collection of business objects that are structured hierarchically:

MetadataNode
--LongNameEnglish::string
--LongNameArabic::string
--Nodes::BindingList<MetadataNode>

I take this hierarchical collection and flatten it out so that each node references the Id of its parent node (self-referencing):

--Node 1 (Id:1, ParentId:null)
----Node 1-1 (Id:2, ParentId:1)
----Node 1-2 (Id:3, ParentId:1)

In the attached project, if you run it and select File->Open Data File and browse to and select the Metadata2.xml file that I included in the root of the ZIP archive, then click the add button (the icon with the "+" symbol on top of the treeview control), the code in the AddNode function works as expected--it calls RadTreeView.BeginUpdate(), adds a new item to the datasource (a BindingList<MetadataNode> collection), then calls RadTreeView.EndUpdate(). However, if you run the application and select File->New Data File and click the add button, the same code throws a NullReferenceException when the RadTreeView.EndUpdate() method is called.
1 comment
Jesse Dyck
Posted on: 04 Jul 2012 07:55
I think I have encountered the same problem.
The NullReferenceException was caused by the null value for the ParentId (in your example, for Node 1). IIRC, we prevented the exception by using a non-null value (but allowing the TreeView nodes to have null pa