Treeview in ComboBox remembering expanded state

4 posts, 0 answers
  1. Jeff Bradshaw
    Jeff Bradshaw avatar
    27 posts
    Member since:
    Oct 2008

    Posted 29 Mar 2011 Link to this post

    I've got a TreeView in a combo box that works fine. What I'd like to do is keep track of which nodes are expanded in the treeview between pages (I use the control on multiple pages) I've seen code to do a treeview in a combobox and saving a treeview to a session variable but can't seem to get the combination of the two to work correctlty.

    Anybody have any suggestions?

    TIA - Jeff.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Mar 2011 Link to this post

    Hello Jeff,

    One suggestion I found from one of the forum is to use the GetXML() method to get the current state of RadTreeView as XML string and save the XML string. When you decide to restore your Treeview, call the LoadXmlString() method to populate the treeview from the previously stored XML String.

    Also checkout the code library which would help you in achieving the functionality: Save the expanded state of the TreeNodes when the treeview is being bound upon each postback


    Could you paste the code that you tried if this does not help?


    -Shinu.
  3. Jeff Bradshaw
    Jeff Bradshaw avatar
    27 posts
    Member since:
    Oct 2008

    Posted 30 Mar 2011 Link to this post

    But how can you get at the treeview? When you edit the code, Visual Studio doesn't seem to know about that control (I assume because it's actually a subcontrol of the combo box.) If I could get at the treeview directly, I would try the GetXML/LoadXML but can't figure out how to get at the treeview.
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 31 Mar 2011 Link to this post

    Hello Jeff,

    You can access the controls which is inside RadCombo ItemTemplate like below.

    • Find the RadTreeView server-side:
      RadTreeView tree = (RadTreeView)RadComboBox1.Items[0].FindControl("RadTreeView1")

    • Find the RadTreeView client-side:
      var combo = $find("<%= RadComboBox1.ClientID %>");
      var tree = combo.get_items().getItem(0).findControl("RadTreeView1");
      tree.get_nodes().getNode(1).select();
    Take a look at the following documentation for more on this.
    Accessing Controls Inside Templates

    Thanks,
    Shinu.
Back to Top