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

Add a treeview inside a combo box programatically

4 Answers 114 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Andy Ho
Top achievements
Rank 1
Andy Ho asked on 20 Jul 2010, 02:26 AM
Hi,

I wanted to create a RadCombobox programatically and a radtreeview also need to be there, how can I create/add control to the ITEMTEMPLATE?

My code is something like this:

Dim cbFolder as new RadCombobox
Dim tree as new radTreeView
        'Codes to add nodes to the Treeview
dim li as new radcomboboxitem
li.controls.add(tree)
cbFolder.items.add(li)

The code above created a radcombobox with the treeview but I can't select any node. I think I should add the treeview in an ItemTemplate instead of an item, any advise?

Thanks.

Andy Ho

4 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 20 Jul 2010, 02:16 PM
This article should be of use to you:

http://www.telerik.com/help/aspnet-ajax/combo_templatesaddingtemplates.html

Instead of a label, just add a TreeView.

I hope that helps.
0
Andy Ho
Top achievements
Rank 1
answered on 21 Jul 2010, 01:35 AM
Cori,

Thanks for your reply. But my problem is even the Radcombobox itself is created programatically at Page_Load. So after I created it with:

Dim combo1 as new RadCombobox

how can I add a treeview to it?
0
Cori
Top achievements
Rank 2
answered on 21 Jul 2010, 02:12 PM
In that help article I posted it shows this:

protected void Page_Load(object sender, EventArgs e)
{        
   if (!Page.IsPostBack)
   {
       RadComboBox1.Items.Add(new RadComboBoxItem("RadComboBoxItem4"));
       RadComboBox1.Items.Add(new RadComboBoxItem("RadComboBoxItem5"));
   }  
   LabelTemplate template = new LabelTemplate();
   foreach (RadComboBoxItem item in RadComboBox1.Items)
   {            
       template.InstantiateIn(item);
   }
     
   RadComboBox1.DataBind();
}

So just change it to create the RadComboBox and keep instantiating the template on each page load like the above code.

I hope that helps.

0
Kalina
Telerik team
answered on 23 Jul 2010, 12:44 PM
Hi Andy Ho,

You can create a RadComboBox and then add a RadTreeView in it dynamically by creating a custom ItemTemplate as described at this help article.
I prepared for you a small basic example – please find it attached.
I hope this helps.

All the best,
Kalina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
ComboBox
Asked by
Andy Ho
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Andy Ho
Top achievements
Rank 1
Kalina
Telerik team
Share this question
or