Results 1 to 9 of 9
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Move treeview node (XP 2003)

    I am trying to use drag and drop to move nodes in my tree view. So far I can select the mode being moved and I can get teh node that it is dropped on. If I drop on a parent node the following code works just fine -
    Set nodSelected.Parent = nodDrop
    and puts the moved node at the top of the list. What I can't get to happen is to put the moved node just below the node it's dropped on when they are both children of the same parent node. I tried using the .index but it's read only. An ideas on how to do this?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Move treeview node (XP 2003)

    I don't understand "to put the moved node just below the node it's dropped on" - if you drop on a node, that node becomes the new parent of the dropped node, not a sibling according to the line of code you posted.
    Perhaps you could post (a stripped down copy of) the database?

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Move treeview node (XP 2003)

    I am not trying to move the node to a different parent - I just want to change the order in which the nodes are displayed.

    The code I showed works for changing the node's parent or moving it to be the top node for the existing parent.

    So now I just want to rearrange the order in which the children are displayed.

    Does that make sense?

    Maybe I need to remove the old node and create a new one but how do I change the index order when I'm trying to insert the node between other nodes with the same parent?

    When the mode is moved, I can get the key of the item I drop on, so that I can modify the sort order in the recordset used to populate the treeview. But then if I rebuild the treeview I get lots of flashing.

  4. #4
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Move treeview node (XP 2003)

    i did find this code that looked like it might work but the insert command isn't recognised
    DraggedNode.Parent.Nodes.Remove(DraggedNode);
    DropNode.Parent.Nodes.Insert(DropNode.Index+1, DraggedNode)

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Move treeview node (XP 2003)

    That is code for Visual Basic .Net, not for VBA.

  6. #6
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Move treeview node (XP 2003)

    is there a vba equivalent or another way to do it?

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Move treeview node (XP 2003)

    No, there is no VBA equivalent, I think you'll have to rebuild the children at the appropriate level. But perhaps someone with more experience will have a better suggestion.

  8. #8
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Move treeview node (XP 2003)

    Thanks Hans - I've been looking everywhere and just can't find anything that will work in VBA.

  9. #9
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Move treeview node (XP 2003)

    I found the answer -
    get the key, text tag and image from the selectednode then

    oTree.Nodes.Remove nodSelected.Index
    oTree.Nodes.Add nodDrop.Key, tvwNext, strNewNodeKey, strNewNodeText, strNewNodeImage
    oTree.Nodes(strNewNodeKey).Tag = strNewNodeTag

    using the dropped on node and tvwNext puts it just after the node you drop

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •