?
Solved

TreeView Control

Posted on 2003-02-26
4
Medium Priority
?
292 Views
Last Modified: 2010-05-01
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
Comment
Question by:alexl22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 2

Accepted Solution

by:
CD-Softy earned 100 total points
ID: 8028653
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
 
LVL 1

Assisted Solution

by:sazhagianambi
sazhagianambi earned 100 total points
ID: 8031159
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
 

Expert Comment

by:CleanupPing
ID: 8901066
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 8983452
Moderator, my recommended disposition is:

    Split points between: CD-Softy and sazhagianambi

DanRollins -- EE database cleanup volunteer
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question