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

Telerik RadTree inside combo box ?

3 Answers 64 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Seabus
Top achievements
Rank 1
Seabus asked on 25 Aug 2011, 12:29 AM
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

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Aug 2011, 07:59 AM
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.
0
Seabus
Top achievements
Rank 1
answered on 25 Aug 2011, 05:54 PM
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
0
Ivana
Telerik team
answered on 29 Aug 2011, 03:59 PM
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 >>

Tags
ComboBox
Asked by
Seabus
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Seabus
Top achievements
Rank 1
Ivana
Telerik team
Share this question
or