Skip to main content

TreeList.GetCustomSummaryValue Event

Allows you to specify custom summary values when the control is displayed on-screen.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v24.1.dll

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

Declaration

public event GetCustomSummaryValueEventHandler GetCustomSummaryValue

Event Data

The GetCustomSummaryValue event's data class is GetCustomSummaryValueEventArgs. The following properties provide information specific to this event:

Property Description
Column Obtains the Tree List column used by the summary calculations.
CustomValue Gets or sets a value to be displayed within a summary.
IsSummaryFooter Gets a value indicating whether the total or group summary value is to be calculated.
Nodes Gets the nodes collection for which to calculate a custom summary.

Remarks

The control can display the following summaries:

The control supports five predefined aggregate functions: Sum, Min, Max, Count, and Average. If these functions do not meet your needs, you can enable Custom mode and handle the GetCustomSummaryValue event to specify a custom summary value.

The Nodes event argument accesses the processed node collection. To enumerate nodes, you can use either a recursive method or an iterator. See the following help topic for more information: Tree Traversal. Use the CustomValue argument to specify a custom summary value.

The GetCustomSummaryValue event allows you to specify custom summary values when the control is displayed on-screen. To specify custom summary values when the control is printed, use the GetPrintCustomSummaryValue event.

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.

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;
   }
}
See Also