Skip to main content

How to: Implement a custom summary

The following example calculates the number of records for which the “Budget” column’s value exceeds 500,000. The setCustomSummary method sets the custom summary type for the Budget column. The TreeList.GetCustomSummaryValue event handler implements the calculation logic.

The image below shows the result.

CustomSummary

private void setCustomSummary() {
   treeList1.OptionsView.ShowRowFooterSummary = true;
   treeList1.Columns["Budget"].RowFooterSummary = SummaryItemType.Custom;
   treeList1.Columns["Budget"].RowFooterSummaryStrFormat = "{0} nodes exceed limit";
}

private void treeList1_GetCustomSummaryValue(object sender, DevExpress.XtraTreeList.GetCustomSummaryValueEventArgs e) {
   if(e.Column.FieldName == "Budget") {
      IEnumerator en = e.Nodes.GetEnumerator();
      int exceedingLimitNodes = 0;
      while(en.MoveNext()) {
         TreeListNode node = (TreeListNode)en.Current;
         decimal budget = (decimal)node.GetValue(e.Column);
         if(budget > 500000) {
            exceedingLimitNodes ++;
            //...
         }
      }
      e.CustomValue = exceedingLimitNodes;
   }
}