Back to Devexpress

TreeList.NodesIterator Property

windowsforms-devexpress-dot-xtratreelist-dot-treelist-f22ff5d5.md

latest5.7 KB
Original Source

TreeList.NodesIterator Property

Gets an object that enables you to perform specific operations on a set of nodes.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

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

Declaration

csharp
[Browsable(false)]
public TreeListNodesIterator NodesIterator { get; }
vb
<Browsable(False)>
Public ReadOnly Property NodesIterator As TreeListNodesIterator

Property Value

TypeDescription
TreeListNodesIterator

A TreeListNodesIterator object used to perform predefined operations on a set of nodes.

|

Remarks

You may often need to traverse through nodes of the Tree List control. This can be used to perform a specific operation on each node, find a node by the specified criterion or calculate the value of some aggregate function over nodes. Since the nodes are represented in a tree-like structure, all nodes can be visited using a recursive function. However, the Tree List control enables you to avoid writing such a function. You can visit all nodes or a predefined set of nodes using the nodes iterator returned by the NodesIterator property.

Example

The following sample code declares a new node operation class. This class can be used to calculate the number of nodes in which the specified field value is greater than the predefined limit. The code also handles the TreeList.GetCustomSummaryValue event. This is used to calculate the number of nodes that have a value greater than 500,000 in the Budget field.

Note : you must set a column’s TreeListColumn.SummaryFooter property to SummaryItemType.Custom to make use of the TreeList.GetCustomSummaryValue event.

csharp
using DevExpress.XtraTreeList;

// declaring the custom operation class
public class TreeListExceedLimitOperation : TreeListOperation {
   private string fieldName;
   private int upperLimit;
   private int result;

   public TreeListExceedLimitOperation(string fieldName, int upperLimit) {
      this.fieldName = fieldName;
      this.upperLimit = upperLimit;
      result = 0;
   }
   // incrementing the counter if the node's value exceeds the limit
   public override void Execute(TreeListNode node) {
      int nodeValue = Convert.ToInt32(node[fieldName]);
      if (nodeValue > upperLimit)
         result++;
   }
   public int Result {
      get { return result; }
   }
}

// ...
// using the created class to calculate the number of nodes
// that have a value greater than 500000 in their Budget field
private void treeList1_GetCustomSummaryValue(object sender, GetCustomSummaryValueEventArgs e) {
   if (e.IsSummaryFooter) {
      TreeListExceedLimitOperation operation = 
        new TreeListExceedLimitOperation("Budget", 500000);
      treeList1.NodesIterator.DoOperation(operation);
      e.CustomValue = operation.Result;
   }
}
vb
Imports DevExpress.XtraTreeList

' declaring the custom operation class
Public Class TreeListExceedLimitOperation
   Inherits TreeListOperation

   Private FieldName As String
   Private UpperLimit As Integer
   Private _result As Integer

   Public Sub New(ByVal FieldName As String, ByVal UpperLimit As Integer)
      Me.FieldName = FieldName
      Me.UpperLimit = UpperLimit
      _result = 0
   End Sub

   ' incrementing the counter if the node's value exceeds the limit
   Public Overrides Sub Execute(ByVal Node As TreeListNode)
      Dim NodeValue As Integer = Convert.ToInt32(Node(FieldName))
      If NodeValue > UpperLimit Then _result += 1
   End Sub

   Public ReadOnly Property Result() As Integer
      Get
         Return _result
      End Get
   End Property
End Class

' ...
' using the created class to calculate the number of nodes
' that have a value greater than 500000 in their Budget field
Private Sub TreeList1_GetCustomSummaryValue(ByVal sender As Object, _
ByVal e As GetCustomSummaryValueEventArgs) Handles TreeList1.GetCustomSummaryValue
   If (e.IsSummaryFooter) Then
      Dim Operation As New TreeListExceedLimitOperation("Budget", 500000)
      TreeList1.NodesIterator.DoOperation(Operation)
      e.CustomValue = Operation.Result
   End If
End Sub

See Also

GetNodeList()

TreeListOperation

TreeListVisibleNodeOperation

TreeListNodesIterator

Tree Traversal

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace