Jump to content
  • Advertisement
Sign in to follow this  
PumpkinPieman

[.net] Switching Tree Nodes

This topic is 4440 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do you reorder tree nodes without copying them, wiping the tree view then placing them back. I'm trying to make a simple section of code that shift a node upwards (so you can reorder nodes in a treeview manually), but I can't think of any way else to do it. Thanks

Share this post


Link to post
Share on other sites
Advertisement
Well each node in the tree has a collection of other nodes. So all you should have to do Add the node to its new parent, and remove it from the old.

Basically something like this:


'first you add the node to the new parent.
NewParentNode.Nodes.Add(OldParent.Items(NodeIndex))
'now remove it from the old parent
OldParentNode.Nodes.Remove(OldParent.Items(NodeIndex))
'Alternativly you can use the RemoveAt method:
'OldParentNode.Nodes.RemoteAt(NodeIndex)




this assumes that NodeIndex is the index of the node you want.
you could find the selected node by using the SelectedNode member of the Treeview control. Then to determine the selected node's parent, you can use SelectedNode.Parent.

Now if you are talking about the order of the children in a single node, then you only have use the TreeNodeCollection Insert and RemoveAt/Remove methods. You remove the node from the collection, then Insert to put the node back in its new place. I'm not sure about removeing first, and inserting, or insert then remove... I'm not sure what would happen if you tried putting the same node in the collection twice.

If it helps, check out the documentation on the TreeView, TreeNode, and TreeNodeCollection

[Edited by - zangetsu on May 21, 2006 5:22:39 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!