How to populate the nodes into the newtreeview1 which is the instance of the another treeview1 ? The nodes which is added to the "newtreeview1" should be available in the first instance of the treeview1?
for example; if the treeview1 contains
|-- Node1
|-- Node2
| -- Node3
|-- Node4
the newtreeview1 should also have the above nodes.
you can do this by cloning each node like this
private void CopyNodes(TreeView srcTree, TreeView dstTree)
{
var ar = System.Array.CreateInstance(typeof(TreeNode), srcTree.Nodes.Count);
treeView1.Nodes.CopyTo(ar, 0);
foreach (TreeNode item in ar)
{
dstTree.Nodes.Add((TreeNode)item.Clone());
}
}
and call the function
CopyNodes(treeView1, treeView2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With