TreeNodeEnumerator Constructor

Constructor

Definition

Namespace: EWSoftware.ListControls
Assembly: EWSoftware.ListControls (in EWSoftware.ListControls.dll) Version: 2023.4.9.0
public TreeNodeEnumerator(
	TreeNode start,
	bool enumerateSiblings
)

Parameters

start  TreeNode
The node at which to start enumeration
enumerateSiblings  Boolean
True to enumerate the starting node's siblings as well or false to stop after enumerating the starting node and all of its children.

Example

C# - Enumerate the entire tree
txtEnumResults.Text = null;

// Use foreach() on the ExtendedTreeView control itself to
// enumerate all of its nodes recursively.
foreach(TreeNode node in tvExtTree)
    txtEnumResults.AppendText($"{new String(' ', node.Level * 4)}{node.Text}\r\n");
VB.NET - Enumerate the entire tree
Dim node As TreeNode
txtEnumResults.Text = Nothing

' Use For Each on the ExtendedTreeView control itself to enumerate all of its nodes recursively
For Each node in tvExtTree
    txtEnumResults.AppendText($"{New String(" "C, node.Level * 4)}{node.Text}" & Environment.NewLine)
Next
C# - Enumerate starting at a selected node
bool enumerateSiblings = (sender == btnEnumNodeSibs);
TreeNode node, startNode = tvExtTree.SelectedNode;

if(startNode == null)
{
    txtEnumResults.Text = "Select a starting node first";
    return;
}

txtEnumResults.Text = null;

// For this, we create the enumerator manually and pass it
// the starting node and a flag indicating whether or not
// to enumerate the siblings of the starting node as well.
TreeNodeEnumerator enumerator = new TreeNodeEnumerator(startNode,
    enumerateSiblings);

// Call the MoveNext() method to move through each node.  Use the
// Current property to access the current node.
while(enumerator.MoveNext())
{
    node = enumerator.Current;

    txtEnumResults.AppendText($"Manual Enum: {new String(' ', node.Level * 4)}{node.Text}\r\n");
}

txtEnumResults.AppendText("\r\n\r\n");

// We can also use the helper method to simplify it
foreach(TreeNode tn in TreeNodeEnumerator.Enumerate(startNode, enumerateSiblings))
    txtEnumResults.AppendText($"Enum Helper: {new String(' ', tn.Level * 4)}{tn.Text}\r\n");
VB.NET - Enumerate starting at a selected node
Dim enumerateSiblings As Boolean = False
Dim node As TreeNode
Dim startNode As TreeNode = tvExtTree.SelectedNode

If sender Is btnEnumNodeSibs Then
    enumerateSiblings = True
End If

If startNode Is Nothing Then
    txtEnumResults.Text = "Select a starting node first"
    Return
End If

txtEnumResults.Text = Nothing

' For this, we create the enumerator manually and pass it the starting
' node and a flag indicating whether or not to enumerate the siblings
' of the starting node as well.
Dim enumerator As New TreeNodeEnumerator(startNode, enumerateSiblings)

' Call the MoveNext() method to move through each node.  Use the Current
' property to access the current node.
Do While enumerator.MoveNext()
    node = enumerator.Current

    txtEnumResults.AppendText($"Manual Enum: {New String(" "C, node.Level * 4)}{node.Text}" &
        Environment.NewLine)
Loop

txtEnumResults.AppendText(Environment.NewLine & Environment.NewLine)

' We can also use the helper method to simplify it
For Each node In TreeNodeEnumerator.Enumerate(startNode, enumerateSiblings)
    txtEnumResults.AppendText($"Enum Helper: {New String(" "C, node.Level * 4)}{node.Text}" &
        Environment.NewLine)
Next

See Also