Link to home
Start Free TrialLog in
Avatar of campinas
campinas

asked on

Re-order Nodes in TreeView

In VB6, using the TreeView control:

I need to let the user re-order nodes under a parent node, manually, by drag and drop (question is not about drag and drop details).
When I drop the source node, I can add a copy to the target position and delete the source node. However, this gets complicated when the source node has children.
Unfortunately, the Previous and Next properties of a node are read-only.

QUESTION is,
What wuld be an elegant method of moving nodes around, under the same parent ?
Avatar of AzraSound
AzraSound
Flag of United States of America image

To move the nodes around all you should have to do is alter the Parent, e.g.,

Set movingNode.Parent = TreeView.Nodes(newParentNode.Key)
Avatar of campinas
campinas

ASKER

In my case the parent is the same.
SOLUTION
Avatar of AzraSound
AzraSound
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You should use the Previous /Next properties of a Node object. This make the entire operation similar to moving an object in a double linked list.
As easy as 123. :)

Regards,
TILL
TILL, Previous and Next properties are read-only.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Moving nodes by changing parent doesn't give control over position under the new parent... Rebuilding the node is however not apealing for large nodes... It would be nice to have this "move in branch" feature built into the TreeView control. Thank you both for your hints!