Treeview does not refresh to show childnode moved from one parent node to another
- by mike
I am using the Windows Forms TreeView class which contains a set of TreeNodes. The TreeNodes can have child nodes.
I have a root node with 2 sub nodes (Node1 and Node2)
Node1 has 2 subnodes (child1 and child2)
I have a function that will allow a user to select any node and move it to another node:
TreeNode SelectNode = this.TreeView1.SelectedNode;
TreeNode DestNode = SelectedNewNode(); //function to select a new node
SelectedNode.Remove();
DestNode.Nodes.Add(SelectedNode);
this.TreeView1.Refresh();
When this executes, the current selected node (child2) is removed from its current parent
(Node1) and added to Node2.
However, the Refresh() method of the TreeView control does not show that child2 is under Node2. If I debug it and look at the Nodes collection in the TreeView i do see that child2 is under Node2.
Can anyone tell me why the Refresh() method does not redraw the new parent to child mapping?
Is there a way to tell the TreeView to redraw with the new mappings?