How to databind using datatable under a default root node

3 posts, 0 answers
  1. CSurieux
    CSurieux avatar
    465 posts
    Member since:
    Jan 2007

    Posted 08 Jan 2009 Link to this post

    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. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 08 Jan 2009 Link to this post

    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.
  3. CSurieux
    CSurieux avatar
    465 posts
    Member since:
    Jan 2007

    Posted 08 Jan 2009 Link to this post

    Hello Albert,

     

    Thanks for extremely fast answer !

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

    CS

Back to Top