public class TreeNodeEnumerator : IEnumerator
Public Class TreeNodeEnumerator
Implements IEnumerator
public ref class TreeNodeEnumerator : IEnumerator
type TreeNodeEnumerator =
class
interface IEnumerator
end
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");
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
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");
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
TreeNodeEnumerator | Constructor |
Current | Type-safe enumerator Current method |
Enumerate | This method can be used to enumerate tree nodes in a more convenient way using a foreach loop without having to manually construct and manage the enumerator. |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) |
GetHashCode | Serves as the default hash function. (Inherited from Object) |
GetType | Gets the Type of the current instance. (Inherited from Object) |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) |
MoveNext | Move to the next element |
Reset | Reset the enumerator to the start |
ToString | Returns a string that represents the current object. (Inherited from Object) |