The Execute method is automatically called for each node visited by the nodes iterator. The currently visited node is transmitted to it as the node parameter. This method is used to implement an operation or the calculation logic performed by the iterator. For instance, the operation may involve calculating the number of nodes that satisfy a specific condition. In this case, the Execute method must check whether the node satisfies the condition and increment a counter, if so.
The Execute method can be performed if the CanContinueIteration property returns true.
Most internal operations against nodes are implemented using the nodes iterator. The following examples illustrate how the iterator can be used and in what way the Execute method is implemented.
- Calculating the number of nodes within the XtraTreeList. The Execute method increments a counter.
- Expanding/collapsing all nodes within the XtraTreeList. The Execute method expands or collapsed the currently visited node.
- Printing nodes of the Tree List control. The Execute method prints the currently visited node.

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.
C# |
using DevExpress.XtraTreeList;
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;
}
public override void Execute(TreeListNode node) {
int nodeValue = Convert.ToInt32(node[fieldName]);
if (nodeValue > upperLimit)
result++;
}
public int Result {
get { return result; }
}
}
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
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
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
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
|