Visual Basic: Windows Controls

Visual Studio 6.0

Sorted Property (TreeView Control)

See Also    Example    Applies To

  • Returns or sets a value that determines whether the child nodes of a Node object are sorted alphabetically.

  • Returns or sets a value that determines whether the root level nodes of a TreeView control are sorted alphabetically.

Syntax

object.Sorted [ = boolean]

The Sorted property syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
boolean A Boolean expression specifying whether the Node objects are sorted, as described in Settings.

Settings

The settings for boolean are:

Setting Description
True The Node objects are sorted alphabetically by their Text property. Node objects whose Text property begins with a number are sorted as strings, with the first digit determining the initial position in the sort, and subsequent digits determining sub-sorting.
False The Node objects are not sorted.

Remarks

The Sorted property can be used in two ways: first, to sort the Node objects at the root (top) level of a TreeView control and, second, to sort the immediate children of any individual Node object. For example, the following code sorts the root nodes of a TreeView control:

Private Sub Command1_Click()
   TreeView1.Sorted = True   ' Top level Node objects are sorted.
End Sub

The next example shows how to set the Sorted property for a Node object as it is created:

Private Sub Form_Load()
   Dim nodX As Node
   Set nodX = TreeView1.Nodes.Add(,,,"Parent Node")
   nodX.Sorted = True
End Sub

Setting the Sorted property to True sorts the current Nodes collection only. When you add new Node objects to a TreeView control, you must set the Sorted property to True again to sort the added Node objects.

Show: