Library code snippets

Treeview Reverse Sorting

you may have a treeview like this:

Main Node
  + The Parent
   | - A
   | - B
   | - C
   | - D


This routine will sort Z-A
so the result should be

Main Node
  + The Parent
   | - D
   | - C
   | - B
   | - A


Private Sub Command1_Click()
   Dim tvn As Node
   Dim tvn2 As Node
   
   sName = 1  ' Change Node 1
   ' or sName = "MyNodeName"
   
   Set tvn = TreeView1.Nodes(sName)
   tvn.Sorted = True   ' firstly sort A-Z  then we simply replace last items with the first ones
   tvn.Sorted = False
   
   chil = tvn.Children: If chil = 0 Then Exit Sub     ' if no children the exit
   Set tvn = tvn.Child.LastSibling
   
   For a = 1 To chil
       Set tvn2 = tvn
       
       Set tvn = tvn.Previous
       TreeView1.Nodes.Remove tvn2.Index
               
       TreeView1.Nodes.Add sName, 4, tvn2.Key, tvn2
   Next
End Sub

Comments

  1. 01 Jan 1999 at 00:00

    This thread is for discussions of Treeview Reverse Sorting.

Leave a comment

Sign in or Join us (it's free).

Kym Manson Till the Roof comes off Till the Lights go out Till my Legs give out Can't shut my mouth I will not fall, my Wisdoms all.

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

We'd love to hear what you think! Submit ideas or give us feedback