Back to Devexpress

TreeListOperation.NeedsVisitChildren(TreeListNode) Method

windowsforms-devexpress-dot-xtratreelist-dot-nodes-dot-operations-dot-treelistoperation-dot-needsvisitchildren-x28-devexpress-dot-xtratreelist-dot-nodes-dot-treelistnode-x29.md

latest5.4 KB
Original Source

TreeListOperation.NeedsVisitChildren(TreeListNode) Method

Gets a value specifying whether the operation must be performed on the specified node’s children.

Namespace : DevExpress.XtraTreeList.Nodes.Operations

Assembly : DevExpress.XtraTreeList.v25.2.dll

NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList

Declaration

csharp
public virtual bool NeedsVisitChildren(
    TreeListNode node
)
vb
Public Overridable Function NeedsVisitChildren(
    node As TreeListNode
) As Boolean

Parameters

NameTypeDescription
nodeTreeListNode

A TreeListNode object representing the node whose child nodes are to be visited.

|

Returns

TypeDescription
Boolean

true if the operation must be performed on the specified node’s children; otherwise false.

|

Remarks

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.

csharp
public class TreeListCustomCountOperation : TreeListOperation {
   private int count;

   public TreeListCustomCountOperation() {
      count = 0;
   }
   // the parent node's Location field must contain the Monterey value
   public override bool NeedsVisitChildren(TreeListNode node) {
      return node["Location"].ToString() == "Monterey";
   }
   // only parent nodes must be visited
   public override bool NeedsFullIteration {
      get { return false; }
   }
   public override void Execute(TreeListNode node) {
      count += node.Nodes.Count;
   }
   public int Count {
      get { return count; }
   }
}

//...
// performing the operation and storing its result
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

   ' the parent node's Location field must contain the Monterey value
   Public Overrides Function NeedsVisitChildren(ByVal node As TreeListNode) As Boolean
      Return node("Location").ToString() = "Monterey"
   End Function

   ' only parent nodes must be visited
   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

'...
' performing the operation and storing its result
Dim Operation As New TreeListCustomCountOperation()
TreeList1.NodesIterator.DoOperation(Operation)
Dim Result As Integer = Operation.Count

See Also

Execute(TreeListNode)

TreeListOperation Class

TreeListOperation Members

DevExpress.XtraTreeList.Nodes.Operations Namespace