Back to Devexpress

ASPxTreeList.CustomSummaryCalculate Event

aspnet-devexpress-dot-web-dot-aspxtreelist-dot-aspxtreelist-196c54e6.md

latest4.9 KB
Original Source

ASPxTreeList.CustomSummaryCalculate Event

Enables you to calculate summary values manually.

Namespace : DevExpress.Web.ASPxTreeList

Assembly : DevExpress.Web.ASPxTreeList.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event TreeListCustomSummaryEventHandler CustomSummaryCalculate
vb
Public Event CustomSummaryCalculate As TreeListCustomSummaryEventHandler

Event Data

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

PropertyDescription
NodeGets the node currently being processed. Inherited from TreeListNodeEventArgs.
SummaryItemGets a summary item whose value is being calculated.
SummaryProcessGets the current calculation stage.
ValueGets or sets the summary value.

Remarks

Total summaries and group summaries provide five predefined aggregate functions. These functions allow you to calculate the number of nodes, the maximum and minimum values, the sum and the average value. If you need to calculate a summary value using an aggregate function not included in the predefined set, set the summary item’s TreeListSummaryItem.SummaryType property to SummaryItemType.Custom and handle the CustomSummaryCalculate event.

The CustomSummaryCalculate event fires for each node displayed within the ASPxTreeList. Additionally, the event is raised before and after processing nodes. This can be used to perform any initialization and finalization.

For detailed information and examples, see Custom Aggregate Functions.

Example

This example shows how to implement a custom summary calculation.

Create a summary item within the ASPxTreeList.Summary collection and customize its settings as shown below:

The ASPxTreeList.CustomSummaryCalculate event is handled to sum the budgets of selected departments. Finally, set the TreeListSettingsBehavior.ProcessSelectionChangedOnServer option to true.

The image below shows the result:

csharp
using DevExpress.Data;

protected void ASPxTreeList2_CustomSummaryCalculate(object sender,
TreeListCustomSummaryEventArgs e) {
    switch (e.SummaryProcess) {
        case CustomSummaryProcess.Start:
            e.Value = (int)0;
            break;
        case CustomSummaryProcess.Calculate:
            if (e.Node.Selected)
                e.Value = (int)e.Value + (int)e.Node["Budget"];
            break;
        case CustomSummaryProcess.Finalize:
            break;
    }
}
vb
Imports DevExpress.Data

Protected Sub ASPxTreeList2_CustomSummaryCalculate(ByVal sender As Object,_
ByVal e As TreeListCustomSummaryEventArgs)
   Select Case e.SummaryProcess
      Case CustomSummaryProcess.Start
         e.Value = CInt(Fix(0))
      Case CustomSummaryProcess.Calculate
         If e.Node.Selected Then
            e.Value = CInt(Fix(e.Value)) + CInt(Fix(e.Node("Budget")))
         End If
      Case CustomSummaryProcess.Finalize
   End Select
End Sub

See Also

Data Summaries (Tree List)

Custom Aggregate Functions

Tree List

ASPxTreeList Class

ASPxTreeList Members

DevExpress.Web.ASPxTreeList Namespace