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

combobox with treeview setting initially selected value

1 Answer 141 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
KevinMc
Top achievements
Rank 1
KevinMc asked on 14 Jul 2008, 07:45 PM
I am trying to set the selected value of the combobox/treeview from a database value. The online example of a treeview in a combobox works great for insert and select operations but if i try to use it in an edit form i can't seem to properly find the treeview in the combobox and set the selected item to the database field. Any examples out there that explain how to do this?

<telerik:RadComboBox ID="comboParent" runat="server">  
                    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
                    <ItemTemplate> 
                        <div id="divParentProducts">  
                            <telerik:RadTreeView ID="treeParentProducts" runat="server" DataFieldID="ProductID" DataFieldParentID="ParentProductID" 
                                DataSourceID="sqlProducts" DataTextField="ProductName" DataValueField="ProductID" OnClientNodeClicking="productClicking" 
                                Skin="WebBlue">  
                                <CollapseAnimation Type="OutQuint" Duration="100"></CollapseAnimation> 
                                <ExpandAnimation Duration="100"></ExpandAnimation> 
                            </telerik:RadTreeView> 
                        </div> 
                    </ItemTemplate> 
                    <Items> 
                        <telerik:RadComboBoxItem Text="" Value="" /> 
                    </Items> 
                </telerik:RadComboBox> 
 


//Found this in another forum answer what would the "THE _ITEM_VALUE" Be in my scenario  
RadComboBoxItem comboBoxItem = comboParent.FindItemByValue("THE_ITEM_VALUE");  
RadTreeView treeView = (RadTreeView)comboBoxItem.FindControl("treeProductHierarchy");  
TreeNode nodetoSelect = parentProducts.FindNode(selected.ParentProductID.ToString());  
nodetoSelect.Selected = true

1 Answer, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 15 Jul 2008, 09:18 AM
Hi KevinMc,

Have you tried this:

RadComboBoxItem comboBoxItem = comboParent.FindItemByValue("THE_ITEM_VALUE");     
RadTreeView treeView = (RadTreeView)comboBoxItem.FindControl("treeProductHierarchy");     
TreeNode nodetoSelect = treeView.FindNodeByValue(selected.ParentProductID.ToString());     
nodetoSelect.Selected = true;    
 

Make sure that comboBoxItem is not null (e.g. you need to have a combo item with Value = "The_ITEM_VALUE")

Let us know how it goes.

Sincerely yours,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ComboBox
Asked by
KevinMc
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Share this question
or