Child, FirstSibling, LastSibling, Previous, Parent, Next, and Root Properties (Node)

Purpose

The Child, FirstSibling, LastSibling, Previous, Parent, Next, and Root properties all return a reference to another Node object.

Syntax

Node.Child

Node.FirstSibling

Node.LastSibling

Node.Previous

Node.Parent

Node.Next

Node.Root

Description

Child - Returns a reference to the first child of a Node object in a TreeView control.

FirstSibling - Returns a reference to the first sibling of a Node object in a TreeView control. The first sibling is the Node that appears in the first position in one level of a hierarchy of nodes. Which Node actually appears in the first position depends on whether or not the Node objects at that level are sorted, which is determined by the Sorted property.

LastSibling - Returns a reference to the last sibling of a Node object in a TreeView control. The last sibling is the Node that appears in the last position in one level of a hierarchy of nodes. Which Node actually appears in the last position depends on whether or not the Node objects at that level are sorted, which is determined by the Sorted property. To sort the Node objects at one level, set the Sorted property of the Parent node to True.

Previous - Returns a reference to the previous sibling of a Node object.

Parent - Returns or sets the parent object of a Node object. An error occurs if you set this property to an object that creates a loop. For example, you cannot set any Node to become a child Node of its own descendants.

Next - Returns a reference to the next sibling Node of a TreeView control's Node object.

Root - Returns a reference to the root Node object of a selected Node.

Example

Dim n As Node, nd As Nodes

Ocx TreeView tv = "", 0, 0, 200, 300

.Style = tvwTreelinesPlusMinusText  : .LineStyle = tvwRootLines

Set n = tv.AddItem( , , "Bert" , "Bert")                // Node 1

Set nd = tv.Nodes

Set n = nd.AddChild("Bert" , "Harry" , "Harry")         // Node 2

Set n = tv.Nodes.AddChild("Bert", "Charlie", "Charlie") // Node 3

Set n = tv.Nodes.Add(3, tvwChild , "Mary" , "Mary")     // Node 4

nd.AddChild "Mary", "Bertha" , "Bertha"                 // Node 5

nd.AddChild "Bert", "Arthur" , "Arthur"                 // Node 6

tv.Node(5).EnsureVisible

'

Debug.Show

Trace tv!Charlie.Child.Text

Trace tv.Nodes("Charlie").FirstSibling.Text

Trace tv.Nodes("Charlie").Next.Text

Trace tv!Charlie.LastSibling.Text

Trace tv!Charlie.Previous.Text

Trace tv(3).Parent.Text

Trace tv!Charlie.Root.Text

Do : Sleep : Until Me Is Nothing

Remarks

There are many ways to access a Node element.

NOTE: Caution should be exercised when interrogating the Child, Previous and Next properties: if a referenced node does not exist, a 'Object is Nothing' error is triggered as can be seen if the following line is added to the example above:

Trace tv!Harry.Previous.Text

See Also

TreeView, Node, Nodes

{Created by Sjouke Hamstra; Last updated: 25/09/2014 by James Gaite}