When traversing through nodes using the nodes iterator, you can specify which nodes from the specified range are to be visited using the NeedsFullIteration property and the NeedsVisitChildren method. The list below describes the relationship between these two members.
- The NeedsFullIteration property is set to true. In this case, if the NeedsVisitChildren method returns false for a parent node, this node's children are not visited.
- The NeedsFullIteration property is set to false. In this case, only nodes that have children are visited. If the NeedsVisitChildren method returns false for a parent node, it is omitted (together with its children).
For instance, when you want to traverse through nodes that are not hidden within collapsed groups, children of collapsed nodes must not be visited. Thus, you can return the tested node's TreeListNode.Expanded property value in the implementation of the NeedsVisitChildren method.

Example
The following sample code declares the TreeListCustomCountOperation operation class. It can be used to calculate the number of nodes whose parent contains the value of "Monterey" in its Location field.
The operation is performed by calling the TreeListNodesIterator.DoOperation method. Its result is stored to the result variable.
C# |
public class TreeListCustomCountOperation : TreeListOperation {
private int count;
public TreeListCustomCountOperation() {
count = 0;
}
public override bool NeedsVisitChildren(TreeListNode node) {
return node["Location"].ToString() == "Monterey";
}
public override bool NeedsFullIteration {
get { return false; }
}
public override void Execute(TreeListNode node) {
count += node.Nodes.Count;
}
public int Count {
get { return count; }
}
}
TreeListCustomCountOperation operation = new TreeListCustomCountOperation();
treeList1.NodesIterator.DoOperation(operation);
int result = operation.Count;
|
VB |
Public Class TreeListCustomCountOperation
Inherits TreeListOperation
Private _count As Integer
Public Sub New()
_count = 0
End Sub
Public Overrides Function NeedsVisitChildren(ByVal node As TreeListNode) As Boolean
Return node("Location").ToString() = "Monterey"
End Function
Public Overrides ReadOnly Property NeedsFullIteration() As Boolean
Get
Return False
End Get
End Property
Public Overrides Sub Execute(ByVal node As TreeListNode)
_count += node.Nodes.Count
End Sub
Public ReadOnly Property Count() As Integer
Get
Return _count
End Get
End Property
End Class
Dim Operation As New TreeListCustomCountOperation()
TreeList1.NodesIterator.DoOperation(Operation)
Dim Result As Integer = Operation.Count
|