This is a migrated thread and some comments may be shown as answers.

How to databind using datatable under a default root node

2 Answers 75 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
CSurieux
Top achievements
Rank 2
CSurieux asked on 08 Jan 2009, 11:25 AM
Hello,

As I don't know if I will have content in the datatable I am using as a hierachical datasource for a radtreeview, I want to always have a root node on level 0 and have the hirarchical databinding occuring from level 1.
This to allow adding first node with a contextmenu 'Add' method.
How to do this in codebehind (c#)?
Thanks.

CS

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 08 Jan 2009, 11:36 AM
Hello Christian Surieux,

This is not supported out of the box. I suggest you first databind your treeview and then add a new root node and make all other root nodes its children. Here is some sample code:

treeView.DataSource = GetDataTable();
treeView.DataBind();

RadTreeNode rootNode = new RadTreeNode();

while (treeView.Nodes.Count > 0)
{
    RadTreeNode node = treeView.Nodes[0];
    rootNode.Nodes.Add(node);
}

Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
CSurieux
Top achievements
Rank 2
answered on 08 Jan 2009, 12:05 PM

Hello Albert,

 

Thanks for extremely fast answer !

I thinks it will do the job, happy new year to telerik teams.

CS

Tags
TreeView
Asked by
CSurieux
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
CSurieux
Top achievements
Rank 2
Share this question
or