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

[Solved] Add node in treeview combo

1 Answer 125 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Saima Gul
Top achievements
Rank 1
Saima Gul asked on 16 Mar 2010, 08:38 PM
i am using tree view control and a treeview in combo. both are populated with same source containing same data. i want to add a node in both of them by clicking on button. All is going well and code returns no error but newly added node is shown in one tree not both of them depending on my code order. i.e if i try to ad node in treeview in the last then treeview show it but node is not shown in treeview in combo. if i place my code to add treeview in combo in the last then it is shown in treeview in combo but not in simple treeview control. i can not find out the roblem.
Here is my code to add node

//---Add Node in tree view 
                    RadTreeNode node = new RadTreeNode(); 
                    RadTreeNode pNode; 
                    node.Text = txtGroupAccTitle.Text; 
                    node.Value = txtGroupAccNo.Text; 
                    ////---Add in TreeView in combo 
                    RadTreeView tvwCmbAcc = (RadTreeView)cmbParentAcc.Items[0].FindControl("tvwCmbAcc"); 
                    //----Note:Code returns no error but node is not shown in Combo if this code is placed after next block it shows node in combo but not in left side tree. find its reason 
                    pNode = tvwCmbAcc.FindNodeByValue(cmbParentAcc.SelectedValue.ToString()); 
                    if (pNode != null
                    { 
                        //pNode.Selected = true; 
                        pNode.Nodes.Add(node); 
                        //pNode.Expanded = true; 
                    } 
                    else 
                    { 
                        tvwCmbAcc.Nodes.Add(node); 
                    } 
                    pNode = null
                     
                    //------------------------------------------ 
                    pNode = tvwGrpAccounts.FindNodeByValue(cmbParentAcc.SelectedValue.ToString()); 
                    if (pNode != null
                    { 
                        pNode.Selected = true
                        pNode.Nodes.Add(node); 
                        pNode.Expanded = true
                    } 
                    else 
                    { 
                        tvwGrpAccounts.Nodes.Add(node); 
                    } 


1 Answer, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 17 Mar 2010, 01:36 PM
Hello Saima Gul,

A RadTreeNode object can exist only in one collection. That is why it is added only to one of the treeviews.

What you can do is to add the node in the first treeview and then add a copy of that node to the second tree:

tree.Nodes.Add(node.Clone());


Kind regards,
Veskoni
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
Saima Gul
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Share this question
or