Reputation: 247
How to add nodes dynamically to a already existing treeview?
if an example as,
-Root
-child1
above one is already existing treeview. but i want to add one more node(child2) to the Root, output is like..
-Root
-child1
-child2
Upvotes: 4
Views: 16179
Reputation: 5150
Try this:
TreeNode rootNode = TreeView.Nodes.Cast<TreeNode>().ToList().Find(n => n.Text.Equals("Root"));
if (rootNode != null)
{
rootNode.Nodes.Add("child2");
}
Upvotes: 4
Reputation: 4084
try:
treeView1.Nodes.Add(new TreeNode())
Details are found here: http://msdn.microsoft.com/de-de/library/system.windows.forms.treeview.nodes.aspx
Upvotes: 3
Reputation: 17010
There are three ways to control a control like a tree view:
If you are going to have to have the same treeview either a) appear to multiple people or b) reconsitute after postbacks, I actually like massaging and caching the dataset and binding. It is rather simple and lighter weight than the other options if it is being reused.
Upvotes: 1
Reputation: 21881
I am assuming you are referring to the asp.net TreeView control
MyTreeView.Nodes.Add(new TreeNode() { Text = "Child 2" });
Upvotes: 1