A 'new' type of binding problem?

3 posts, 1 answers
  1. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 18 Sep 2009 Link to this post

    We're using a treeview to provide a navigation tool.

    At a certain level we want to display some hierarchical data.

    Can any one think of a straightforward way of adding hierarchical data to a node in an existing tree without destroying the existing nodes?

    --
    Stuart
  2. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 18 Sep 2009 Link to this post

    Hello Stuart Hemming,

    RadTreeView does not provide bult-in support for this scenario. However I can propose a workaround:

    1. Creating a temporary RadTreeView object and bind the data to it
    2. Traverse all root nodes of the temporary treeview and add them to the existing node in the original treeview

    Regards,
    Albert,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 18 Sep 2009 Link to this post

    Albert,

    Cracking! I didn't think I'd be able to just move nodes like that.

    I added an extension for the RadTreeNode class like this...
    1 namespace UEAPL.Shared.Extensions 
    2
    3     public static class RadTreeNodeExtensions 
    4     { 
    5         public static void AddHierarchy(this RadTreeNode node, object DataSource, string DataTextField, string DataValueField, string DataFieldID, string DataFieldParentID) 
    6         { 
    7             RadTreeView t = new RadTreeView(); 
    8  
    9             t.DataTextField = DataTextField; 
    10             t.DataValueField = DataValueField; 
    11             t.DataFieldID = DataFieldID; 
    12             t.DataFieldParentID = DataFieldParentID; 
    13             t.DataSource = DataSource; 
    14             t.DataBind(); 
    15  
    16             while (t.Nodes.Count > 0) 
    17             { 
    18                 node.Nodes.Add(t.Nodes[0]); 
    19             } 
    20         } 
    21     } 
    22
    23  


Back to Top