Skip to content

Nodes hierarchy

To show a node inside the treeview, you need to add that node to the treeview's Root node or any other parent node in the treeview. To control the nodes hierarchy, use these node properties and methods:

  • Root - root node of a treeview to which this node is bound.
  • Parent - node's parent node. Returns null for all root-level nodes.
  • RealParent - identical to the Parent, but returns the treeview's Root node for all root-level nodes.
  • Nodes - child nodes list.
  • AttachTo - add the node to the specified parent node.
  • To check whether a node is attached to the treeview, use the IsAttached property.

Index#

Every node has its own zero-based unique index within the parent's child nodes that is stored in the Index property. By changing it, you'll move the node forward or backward within the current parent.

Node Index

Level#

Every node has its own nesting level that is stored in the Level property. It defines how deep the node is in the treeview nodes' hierarchy. Root-level nodes have the value 0, root node's children - 1, and so on.

Node Level

Path#

A node may have an unlimited nesting level. To get all of a node's parents, use the Path property. It contains the FullPath property, which returns a node's parents list with the node itself as the first item in the list. Also, you can use the Parents path property, which returns only the node's parents list.

Example

Node n1 = new Node("1");
Node n2 = new Node("2");
n2.AttachTo(n1);
Node n3 = new Node("3");
n3.AttachTo(n2);

// returns: n1, n2, n3.
Node[] hierarchy = n3.Path.FullPath;

// returns: n1, n2.
hierarchy = n3.Path.Parents;
Dim n1 As New Node(1)
Dim n2 As New Node(2)
n2.AttachTo(n1)
Dim n3 As New Node(3)
n3.AttachTo(n2)

' returns: n1, n2, n3.
Dim hierarchy As Node() = n3.Path.FullPath

' returns: n1, n2.
hierarchy = n3.Path.Parents

RealParent#

To optimize work with a node's parent nodes, every node has two properties - Parent and RealParent. While the Parent property returns null for root-level nodes, RealParent always returns a not-NULL value for every node. For root nodes, it returns the treeview's Root node.

TopLevelParent#

To find a node's topmost parent, use the TopLevelParent property.

Example

Node n1 = new Node("1");
Node n2 = new Node("2");
n2.AttachTo(n1);
Node n3 = new Node("3");
n3.AttachTo(n2);
// topParent = n1
Node topParent = n3.TopLevelParent;
Dim n1 As New Node(1)
Dim n2 As New Node(2)
n2.AttachTo(n1)
Dim n3 As New Node(3)
n3.AttachTo(n2)
' topParent = n1
Dim topParent As Node = n3.TopLevelParent

NextSiblingNode, PrevSiblingNode#

If you have a node instance, you can find the next or previous sibling node within the current parent using the NextSiblingNode and PrevSiblingNode node properties respectively.

NextExpandedNode, PrevExpandedNode#

The NextExpandedNode and PrevExpandedNode properties are almost equivalent to the NextSiblingNode and PrevSiblingNode properties, but allow you to get visible sibling nodes within the whole treeview.