Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6554123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:39:47+00:00 2026-05-25T12:39:47+00:00

Ok. I’ve been working a lot on a treeview and I decided that it

  • 0

Ok. I’ve been working a lot on a treeview and I decided that it would be convenient to allow the users to move the nodes of the treeview up and down however they see fit. My structure is just a simple two level treeview, however every root node must have a child. For example:

Root
  child
  child
  child
Root
  child
  child
Root
  child
  child
  child
  child

I have code written where you can only check off one box from the Root nodes at a time. What I want to do is click a button, and have the checked root node move up (or down) one position (of course taking its children with it).

The only way I can imagine this working would be to completely rebuild the node one level higher than it was previously. This seems like it would be far too time consuming when the nodes begin to have more children etc.

When I searched I found a ton of C# results, but since I’m using VBA it didn’t help me at all. If anybody has any suggestions outside of rebuilding the entire node I would love to hear it. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:39:47+00:00Added an answer on May 25, 2026 at 12:39 pm

    The way I solved this was by saving the keys and text of my nodes in temporary variables, clearing the keys, and then switching them.

    At this point, I then loop through all of the children and add them into an array of Nodes. I set the nodes.Parent property of each of them to the opposing node, and then it was all pretty much done.

    This is possible because the data in the table depends on how the user structures the treeview, so once they have the treeview displaying how they want it, I can save the information I need and rebuild it when they open that particular record back up. I hope this is clear but I have some code chunks below to help clear this up.

     Private Sub MoveUP()
     Dim n As Node
     Dim key1 As String
    'etc.....
    
     key1 = n.Key
     text1 = n.Text
     key2 = n.Previous.Key
     text2 = n.Previous.Text
    
    'We have to clear out the keys now.
     n.Key = ""
     n.Previous.Key = ""
    
    'Now replace the keys
     n.Key = key2
     n.Text = text2
     n.Previous.Key = key1
     n.Previous.Text = text1
    
     Call SwitchParents(n, n.Previous)
     End Sub
    

    ^The code above is made to move n up into n.Previous spot
    The following code, is to switch the children of the nodes (if any)

     Private Sub SwitchParents(n1 As Node, n2 As Node)
     Dim nds1() As Node 'Declare with no size to ReDim later
     Dim nds2() As Node
     Dim c As Node 'this is the child node we will use to push into the array
     Dim i As Integer 
    
     i = n1.Children
     ReDim nds1(0 To i)
     Set c = n1.Child
     'Notice in both loops that i remains the number of children, the arrays fill backwards
     'because when you reassign the nodes.Parent property, the node jumps to the beginning,
     'so we pack them backwards and they come out displaying the same way they did before.
     Do While Not (c Is Nothing)
       i = i - 1
       Set nds1(i) = c
       Set c = c.Next
     Loop
    
     i = n2.Children
     ReDim nds2(0 To i)
     Set c = n2.Child
     Do While Not (c Is Nothing)
       i = i - 1
       Set nds2(i) = c
       Set c = c.Next
    Loop
    
    If Not IsEmpty(nds1()) Then
      For i = 0 To UBound(nds1()) - 1
        Set nds1(i).Parent = n2
      Next i
    End If
    
    If Not IsEmpty(nds2()) Then
      For i = 0 To UBound(nds2()) - 1
        Set nds2(i).Parent = n1
      Next i
    End If
    End Sub
    

    I hope this example will help anybody else who has a similar two level tree structure and is looking to do something like this. I am doing it on a button click, however it could be reworked for a drag and drop method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.