Setting Treeview to another Treeview
-
I have a treeview and I want to set another treeview to that treeview when I set TV1 = TV2 and do a breakpoint TV1 looks to have all the nodes, but it doesn't display. Does anyone know what I might have wrong. Thanks.
-
I have a treeview and I want to set another treeview to that treeview when I set TV1 = TV2 and do a breakpoint TV1 looks to have all the nodes, but it doesn't display. Does anyone know what I might have wrong. Thanks.
Hello TreeViews are reference types. That means that TV1 = TV2 will only copy the reference to the same object, but at the end they are still one thing. If you change anything in TV1, it will be also changed in TV2. To copy the whole NodesCollection of one TreeView to another
TreeNode[] TV1Nodes = new TreeNode[TV1.Nodes.Count];
TV1.Nodes.CopyTo(TV1Nodes, 0);
foreach(TreeNode Tn in TV1Nodes)
TV2.Nodes.Add(Tn);Regards:rose: