Telerik RadTree inside combo box ?

4 posts, 0 answers
  1. Seabus
    Seabus avatar
    33 posts
    Member since:
    Jun 2011

    Posted 24 Aug 2011 Link to this post

    Hi,

    I'm trying to insert a telerik tree view inside a telerik combo box ....
    I'm looking at this example:
    http://demos.telerik.com/aspnet-ajax/treeview/examples/functionality/treeviewcombobox/defaultcs.aspx

    The question is how do I go about having a default value for the combo box ...
    In the example above how would I set "Brazil" as the default value for the combo box ?

    Seabus
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Aug 2011 Link to this post

    Hello Seabus,

    Try the following code snippet in the OnClientLoad event of the RadCombobox.
    Javascript:
    function OnClientLoad(sender)
         {
           var tree = $find('<%= RadComboBox1.Items[0].FindControl("RadTreeView1").ClientID %>');
           var node=tree.get_nodes().getNode(1);
           node.select();
           sender.set_text(node.get_text());
        }

    Thanks,
    Shinu.
  3. Seabus
    Seabus avatar
    33 posts
    Member since:
    Jun 2011

    Posted 25 Aug 2011 Link to this post

    Sadly enough this does not work since I'm loading the nodes in the tree manually on my PageLoad function , so I think what happens here is that var node=tree.get_nodes().getNode(1); gets called but there are no nodes loaded at that point.

    Seabus
  4. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 29 Aug 2011 Link to this post

    Hello Seabus,

    You can set a default selected item for the ComboBox in code-behind.
    Here is an example how to do that:
    protected void Page_Load(object sender, System.EventArgs e)
       {
           if (!Page.IsPostBack)
           {
     
               var comboBoxItems = RadComboBox1.Items;
               RadTreeView treeView = (comboBoxItems[0].FindControl("RadTreeView1") as RadTreeView);
               RadTreeNode treeNode = treeView.FindNodeByText("Brazil");
               treeNode.Expanded = true;
               treeNode.Selected = true;
     
               RadComboBox1.Text = treeNode.Text;
           }
       }

    Best wishes,
    Ivana
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top