Treeview does not refresh to show childnode moved from one parent node to another

Posted by mike on Stack Overflow See other posts from Stack Overflow or by mike
Published on 2010-03-23T02:05:00Z Indexed on 2010/03/23 2:11 UTC
Read the original article Hit count: 457

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#