Solved

Sorting a Treeview

Posted on 2001-07-10
5
499 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
[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
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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
Course of the Month4 days, 17 hours left to enroll

636 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