Solved

Sorting a Treeview

Posted on 2001-07-10
5
453 Views
Last Modified: 2008-03-10
I have a Treeview on my form called vbData.  I thought you could just set the Treeviews sorting property to true and it sorts everything alphabetically.  Is this not true.  I have my code below.

    Set ActiveProject = gVBInstance.ActiveVBProject
   
    tvData.Sorted = True
   
    Set nNode = tvData.Nodes.Add()
    nNode.Text = ActiveProject.Name
   
    For Each cmp In ActiveProject.VBComponents
        Set nNode = tvData.Nodes.Add(1, tvwChild)
        iIndex = nNode.Index
        nNode.Text = cmp.Name
    Next
   
0
Comment
Question by:midavis
  • 2
  • 2
5 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 40 total points
ID: 6272003
in fact, the sorted property of the treeview will only sort the root nodes. You have to set the sorted property for every node that will have children:

.

   Set ActiveProject = gVBInstance.ActiveVBProject
   
   tvData.Sorted = True
   
   Set nNode = tvData.Nodes.Add()
   nNode.Text = ActiveProject.Name
   
   For Each cmp In ActiveProject.VBComponents
       Set nNode = tvData.Nodes.Add(1, tvwChild)
       iIndex = nNode.Index
       nNode.Text = cmp.Name
   Next

   'Sort the children of this node
   nNode.Sorted = true

Cheers
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6273773
Did you try putting that statement:
tvData.Sorted = True
Just after all noides were added?
0
 

Author Comment

by:midavis
ID: 6274953
Angel, this seemed to work, sort of.  The last component I add to the tree does not get sorted.  It stays on the top of the node it is supposed to be in.  


    Set ActiveProject = gVBInstance.ActiveVBProject
   
    tvData.Sorted = True
   
    Set nNode = tvData.Nodes.Add()
    nNode.Text = ActiveProject.Name
   
    ' add the main nodes
    For Counter = 1 To 6
        Set nNode = tvData.Nodes.Add(1, tvwChild)
        nNode.Text = mainNodes(Counter)
        nNode.Sorted = True
    Next

This is my updated code.   The mainNodes array holds all the nodes whose parent is the root.  All components I loop through are now added to one of these nodes.  If I have three forms, "frmTest" "frmMain" "frmSimple", in the order they are in the projects, the sorting goes like this.

frmSimple
frmMain
frmTest

Any idea?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6274975
change
nNode.Sorted = True
into
nNode.Parent.Sorted = True

Cheers
     
0
 

Author Comment

by:midavis
ID: 6279081
The answer you sent me angel was pretty close.  I had to manipulate it a bit, but I said I would give you some more points so here you go.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now