Add a treeview inside a combo box programatically

5 posts, 0 answers
  1. Andy Ho
    Andy Ho avatar
    41 posts
    Member since:
    May 2010

    Posted 19 Jul 2010 Link to this post

    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

  2. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 20 Jul 2010 Link to this post

    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.
  3. Andy Ho
    Andy Ho avatar
    41 posts
    Member since:
    May 2010

    Posted 20 Jul 2010 Link to this post

    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?
  4. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 21 Jul 2010 Link to this post

    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.

  5. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 23 Jul 2010 Link to this post

    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
Back to Top