Back to Devexpress

How to: Implement a custom summary

windowsforms-5616-controls-and-libraries-tree-list-examples-summaries-how-to-implement-a-custom-summary.md

latest2.3 KB
Original Source

How to: Implement a custom summary

  • Nov 13, 2018

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.

csharp
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;
   }
}
vb
Private Sub setCustomSummary()
   TreeList1.OptionsView.ShowRowFooterSummary = True
   TreeList1.Columns("Budget").RowFooterSummary = SummaryItemType.Custom
   TreeList1.Columns("Budget").RowFooterSummaryStrFormat = "{0} nodes exceed limit"
End Sub

Private Sub TreeList1_GetCustomSummaryValue(ByVal sender As Object, ByVal e As DevExpress.XtraTreeList.GetCustomSummaryValueEventArgs) _
Handles TreeList1.GetCustomSummaryValue
   If (e.Column.FieldName = "Budget") Then
      Dim en As IEnumerator = e.Nodes.GetEnumerator()
      Dim exceedingLimitNodes As Integer = 0
      Dim node As TreeListNode
      While en.MoveNext() = True
         node = CType(en.Current, TreeListNode)
         Dim budget As Decimal = CType(node.GetValue(e.Column), Decimal)
         If (budget > 500000) Then
            exceedingLimitNodes += 1
            '...
         End If
      End While
      e.CustomValue = exceedingLimitNodes
   End If
End Sub