• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

TreeView Control

I'm working with the treeview control and use this procedure to move the nodes within the treeview:

Private Sub MoveNode(tvw As TreeView, nodX As Node, Direction As String)
Dim nodN As Node
Dim strKey As String
Dim AntKey As String
Dim ActKey As String

  With tvw
    Select Case Direction
      Case "UP"
        If Not nodX.Previous Is Nothing Then
          Set nodN = .Nodes.Add(nodX.Previous, tvwPrevious, , nodX.Text)
        Else
          Exit Sub
        End If
      Case "DOWN"
        If Not nodX.Next Is Nothing Then
          Set nodN = .Nodes.Add(nodX.Next, tvwNext, , nodX.Text)
        Else
          Exit Sub
        End If
    End Select
     
    nodN.Selected = True
     
    If nodX.Children <> 0 Then
      GetChildren tvw, nodX, nodN
    End If
     
    strKey = nodX.Key
    .Nodes.Remove nodX.Index
    Set nodX = Nothing
    nodN.Key = strKey
  End With

End Sub

The problem is that I want to know the actual node Index once I move it.  By example, I have a treeview control with one parent and three children nodes.  I use the function MoveNode() and move the node number 3 (index = 3) to the first position, but it still have the index = 3, when the value that I need is 1, and the second node the value = 2 and the third = 3, and so on.

Could anyone help me!!!!

Thanks in advance.
0
alexl22
Asked:
alexl22
2 Solutions
 
CD-SoftyCommented:
I don't think that is possible. Once a Node object is created and added to the Nodes collection, it is assigned the next available Index number, which exists for the life span of that that node. This can be prooven by setting the Sorted property to True or False, and it won't change the Nodes' index value. I think the approach to take would be to remove all the sibling nodes and then re-add then in the new order you want.

This is similar to the techniqued used to 'move' items up and down a listbox - by removing them first, then re-adding them.
0
 
sazhagianambiCommented:
In Tree View,

If U Rearrange The Childs For One Parent, Then Definetely Those Child Node's Index are in Placing Order Only.

ie, If Root Have Childs Ch1,Ch2,Ch3 as One By One. Then Index Valus are 2,3,4.

If U Change these as Ch2,Ch3,Ch1 Then also Index Valus are
Likely 2,3,4.

  Suppose U Change make any one as a SubNode To another Node then Index Value is assigned inthe Order of,
Root,
ChildNodes,
SubNodesToChildNodes.

So If You Move around within One Parent U can get Index as like u want.

Try Out This Code For More Clarity,

Make One TreeView into the Form

Place One Button ,
Private Sub cmdIndex_Click()
   Dim i As Node
   j = 1
   For Each i In TreeView1.Nodes
      MsgBox "Text= " & TreeView1.Nodes(j).Text & "         Index= " & TreeView1.Nodes(j).Index
      j = j + 1
   Next
End Sub

This Code used to Find out the Index Valus Of the Tree. Try This after u Rearrange Your Nodes.



Cheers,
Nambi


0
 
CleanupPingCommented:
alexl22:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
DanRollinsCommented:
Moderator, my recommended disposition is:

    Split points between: CD-Softy and sazhagianambi

DanRollins -- EE database cleanup volunteer
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now