RadTreeView Binding to Object-relational Data children not populated

1 Answer 61 Views
Treeview
Navid
Top achievements
Rank 1
Navid asked on 28 Feb 2023, 02:26 PM

I am using Telerik UI for Winforms version 2022.1.118.40

I am trying to bind a treeview to a list of object-related data, but only the root nodes are displayed.

My object-related data looks like this:

public class MyRootObject
{
    public string Name {get; set;}
    public List<MyChildObject> ChildObjects {get; set;}
}

public class MyChildObject
{
    public string Name {get; set;}
}

My treeview is set up like this:

var myRootObjects = new List<MyRootObject>()
{
   new MyRootObject()
   {
      Name = "RootName",
      ChildObjects = new List<MyChildObject>()
      {
         Name = "ChildName"
      }
   }
}

MyTreeView.DataSource = myRootObjects;
MyTreeView.ChildMember = "ChildObjects";

 

I have tried different ways of setting the 'ChildMember' property, as per documentation ( https://docs.telerik.com/devtools/winforms/controls/treeview/data-binding/binding-to-object-relational-data ), such as 'myrootObjects\\ChildObjects', but I can not get the child objects to be displayed.

How do I get the child objects to be displayed?

1 Answer, 1 is accepted

Sort by
0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 01 Mar 2023, 07:56 AM

Hello Navid,

The ChildMember needs to start with the type of the main object. Then you can list the collection properties. The DisplayMember property needs to list the properties which will be used on each level. I have extended your code to show one more level of hierarchy. You can find the sample project attached to this reply. 

I hope the attached project will help you to understand how to set up the RadTreeView hierarchy.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Treeview
Asked by
Navid
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or