Treeview in Combo tweak

3 posts, 1 answers
  1. Ed Staffin
    Ed Staffin avatar
    66 posts
    Member since:
    Nov 2008

    Posted 19 Dec 2008 Link to this post

    First off let me say that I LOVE the treeview in the combo trick!
    There is one thing I would like to do that I have quite figured out though.
    In the OnClientDropDownOpenedHandler, you typically write come something like:
    var tree = sender.get_items().getItem(0).findControl(treeid); 
    Where treeid is whatever the id is of the tree in the combo.
    This is great if you have only one combox/treeview control on the. I'm trying to figure out how to genericise the function.
    Right now I have to hard code the control ids in a switch as shown below.



    function OnClientDropDownOpenedHandler(sender, eventArgs)  
    var treeid = "";  
    switch (sender.get_id())  
         case "Master_cntPageBody_ddlOffsetAccount":  
         treeid = "tvOffsetAccount";  
    var tree = sender.get_items().getItem(0).findControl(treeid);  

    What I'd really like to do is to be able to get the id of the tree somehow at runtime so I don't have to have this switch. Is this possible?
    Something  along the lines of 
    I know this doesn't exist but is there some way to get the same effect?
    THanks ... Ed


  2. Answer
    Veselin Vasilev
    Veselin Vasilev avatar
    2992 posts

    Posted 20 Dec 2008 Link to this post

    Hi Ed Staffin,

    One possible solution would be to add a custom attribute to every combo which will contain the ID of the treeview and you will use that attribute as below:

    <telerik:RadComboBox ID="RadComboBox1" runat="server"
        <telerik:RadComboBoxItem TreeViewID="rtTreeView1"/>             

    And then your handler will look like:

    function OnClientDropDownOpenedHandler(sender, eventArgs)   
      var item = sender.get_items().getItem(0);   
      var treeid = item.get_attributes().getAttribute("TreeViewID"); 
      var tree = item.findControl(treeid);   

    I hope this helps.

    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Ed Staffin
    Ed Staffin avatar
    66 posts
    Member since:
    Nov 2008

    Posted 21 Dec 2008 Link to this post

    Hi, thanks for the reply, it pushed me in the right direction. I actually, took your idea and brought it a step further. Instead of setting it on each item, I set the attribute on the parent control on the server side. I think it's a little cleaner.
    Thanks again ... Ed

Back to Top