Solved

Sorting a Treeview

Posted on 2001-07-10
5
443 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 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

19 Experts available now in Live!

Get 1:1 Help Now