Load treelistview from datasource with hardcoded root nodes on treelistview

394 views Asked by At

. Could you please provide me a code sample showing how to load a treelistview from database​ with hardcoded root nodes on treelistview.

I have shared the link below of a sample preview of the tree I am in need of. Rootnodes are hardcoded and I want the child nodes to be populated from a database.

http://tinypic.com/view.php?pic=qnr212&s=5#.Upl6WsSnrh0

Please shed some light here.

Thanks Rahul​

1

There are 1 answers

0
Fares On

To populate a XtraTreeList, you can simply do this :

List<UserDefiniedClass> myListOfObjects = new List<UserDefiniedClass>();
// Here, you could populate your list
// ...
myTreeList.DataSource = myListOfObjects;

According to the child / parent relationship, when defining your class UserDefiniedClass, you have to add two public fields, which are : ID and ParentID (which are of type int).

When you build your list of objects, make sure that :

  • You affect a different ID for each record
  • You affect the parent ID as the child's ParentID
  • You don't affect the ParentID field if the node does not have a parent.

Hope that helps !