Solved

Sorting a Treeview

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

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 143

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Pull multiple cvs files into one access table 28 69
How does CurrentUser work? 10 38
Add and format columns in vb6 7 63
Passing a Text Box name to a Sub 6 99
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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

809 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