Version

GetNodeCount Method (UltraTree)

Returns the number of nodes in the UltraTree.
Syntax
'Declaration
 
Public Function GetNodeCount( _
   ByVal includeSubTrees As Boolean _
) As Integer
public int GetNodeCount( 
   bool includeSubTrees
)

Parameters

includeSubTrees
When True, a count of all nodes in the UltraTree will be returned. When False, a count of only root nodes will be returned.

Return Value

Integer specifying the total number of nodes.
Example
The following sample code illustrates how to calculate the number of nodes in a tree.

Imports Infragistics.Win.UltraWinTree

Private Sub button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button18.Click

    Dim totalNodesInTree As Integer
    Dim nonRootNodes As Integer
    Dim node As UltraTreeNode

    ' Call the tree control's 'GetNodeCount' method 
    ' with true to get the total numder of nodes
    ' in the tree.
    totalNodesInTree = Me.ultraTree1.GetNodeCount(True)

    Debug.WriteLine("Total nodes in tree = " + totalNodesInTree.ToString())
    Debug.Indent()

    ' Get the first root node
    node = Me.ultraTree1.Nodes(0)

    While Not node Is Nothing
        ' Add in root node's descendant nodes.
        nonRootNodes += node.GetNodeCount(True)

        ' Get the next root node
        node = node.GetSibling(NodePosition.Next)
    End While

    Debug.WriteLine("root nodes = " + Me.ultraTree1.Nodes.Count.ToString())
    Debug.WriteLine("non-root nodes = " + nonRootNodes.ToString())
    Debug.IndentLevel = 0

End Sub
using System.Diagnostics;
using Infragistics.Win.UltraWinTree;

private void button18_Click(object sender, System.EventArgs e)
{

	// Call the tree control's 'GetNodeCount' method 
	// with true to get the total numder of nodes
	// in the tree.
	int totalNodesInTree = this.ultraTree1.GetNodeCount( true );

	Debug.WriteLine( "Total nodes in tree = " + totalNodesInTree.ToString());
	Debug.Indent();

	int nonRootNodes = 0;

	// Get the first root node
	UltraTreeNode node = this.ultraTree1.Nodes[0];

	while ( node != null )
	{
		// Add in root node's descendant nodes.
		nonRootNodes += node.GetNodeCount(true);

		// Get the next root node
		node = node.GetSibling( NodePosition.Next );
	}

	Debug.WriteLine( "root nodes = " + this.ultraTree1.Nodes.Count.ToString() );
	Debug.WriteLine( "non-root nodes = " + nonRootNodes.ToString());
	Debug.IndentLevel = 0;

}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also