Is it possible to subclass the RadTreeNode and get it back on a node click. In the image attached I've made a class inheriting from RadTreeNode named FileTreeNode. It kinda works except my custom properties appear but do not have any data. FIleName is null.
Attila Antal
Telerik team
commented on 14 Feb 2023, 11:44 AM
Hi Steven,
By default, the RadTreeView creates RadTreeNodes based on the data source. So I am wondering, in your case, how are the nodes created and added to the TreeView? Is it done automatically by simply binding the Control to data, or you are Creating the TreeNodes and adding them to the treeview's Nodes Collection?
When do you populate the properties FileID, FileName, IsFolder, IsPrivate properties? These things do not get automatically populated by TreeView.
I'm manually adding the nodes to the tree. The nodes I'm adding, FileTreeNode, inherit from RadTreeNode. Something like this:
FileTreeNode objFnode = [routine to create a new FileTreeNode] radTree.Nodes.Add(objFnode);
What's funny is that on a server side node click event, I can cast the DataiIem as a FileTreeNode and I can see the properties in the subclass, i.e. IsPrivate, etc. but there is not data in the subclassed fields.
FileTreeNode objNodeD = (FileTreeNode)e.Node.DataItem; /// no error but but no data
1 Answer, 1 is accepted
0
Attila Antal
Telerik team
answered on 17 Feb 2023, 08:53 AM
Hi Steven,
It is not enough that you add the Node to the TreeView. You will also need to populate them, otherwise, there is no way they will contain values.
I am populating the FileTreeNode with all the data, see the routine above. The returned object is then added to the tree. I stepped through it with a debugger. The RadTreeView only retains it's native data, not the subclassed data for node clicks. I have figured out a workaround, I was just curios if it was a bug or by design.
Attila Antal
Telerik team
commented on 20 Feb 2023, 08:43 AM
Hi Steve,
Inheriting Objects is part of .NET Framework and if there is a problem there, the issue/bug would be with the Framework.
In my test sample data is available. I populated the TreeView with Custom Node objects and those are available later. You can test the code I shared above.
Hi Steven,
By default, the RadTreeView creates RadTreeNodes based on the data source. So I am wondering, in your case, how are the nodes created and added to the TreeView? Is it done automatically by simply binding the Control to data, or you are Creating the TreeNodes and adding them to the treeview's Nodes Collection?
When do you populate the properties FileID, FileName, IsFolder, IsPrivate properties? These things do not get automatically populated by TreeView.
I'm manually adding the nodes to the tree. The nodes I'm adding, FileTreeNode, inherit from RadTreeNode. Something like this:
FileTreeNode objFnode = [routine to create a new FileTreeNode]radTree.Nodes.Add(objFnode);
What's funny is that on a server side node click event, I can cast the DataiIem as a FileTreeNode and I can see the properties in the subclass, i.e. IsPrivate, etc. but there is not data in the subclassed fields.
FileTreeNode objNodeD = (FileTreeNode)e.Node.DataItem; /// no error but but no data