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

Treeview in Combo tweak

2 Answers 27 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ed Staffin
Top achievements
Rank 1
Ed Staffin asked on 19 Dec 2008, 11:01 AM
HI,
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";  
     break;  
}  
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 
sender.get_items().getItem(0).Controls(0).get_id();.
I know this doesn't exist but is there some way to get the same effect?
THanks ... Ed

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 20 Dec 2008, 02:43 PM
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"
<Items> 
    <telerik:RadComboBoxItem TreeViewID="rtTreeView1"/>             
</Items> 
... 

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.

Regards,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Ed Staffin
Top achievements
Rank 1
answered on 21 Dec 2008, 12:06 PM
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

Tags
TreeView
Asked by
Ed Staffin
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Ed Staffin
Top achievements
Rank 1
Share this question
or