The event handler receives an argument of type PivotCustomSummaryEventArgs containing data related to this event.
The following
PivotCustomSummaryEventArgs properties provide information specific to this event.
Property |
Description |
ColumnField |
Gets the column field that corresponds to the current cell. |
ColumnFieldValue |
Gets the value of the Column Field which corresponds to the current cell. |
CustomValue |
Gets or sets a custom summary value. |
DataField |
Gets the data field against which the summary is calculated. |
FieldName |
Gets the name of the Data Field against which the summary is calculated. |
RowField |
Gets the row field that corresponds to the current cell. |
RowFieldValue |
Gets the value of the Row Field which corresponds to the current cell. |
SummaryValue |
Gets an object which contains the values of the predefined summaries that are calculated for the current cell. |
ThreadSafeColumnField |
Gets the column field that corresponds to the current cell. Provides read-only access to field settings. |
ThreadSafeDataField |
Gets the data field against which the summary is calculated. Provides read-only access to field settings. |
ThreadSafeRowField |
Gets the row field that corresponds to the current cell. |
The CustomSummary event is raised when the PivotGridControl calculates its data for display. The CustomSummary event occurs for each Cell that displays the value of the field whose PivotGridField.SummaryType property is set to FieldSummaryType.Custom.
In the event handler you can use the PivotCustomSummaryEventArgs.CreateDrillDownDataSource method to get a list of the records that is the data summarized in the current cell. You can process the data to calculate a custom summary and assign the result to the PivotCustomSummaryEventArgs.CustomValue property.
The PivotGridControl calculates all the predefined summaries (Average, Min, Max, Sum, etc) for each cell. You can access the calculated values using the PivotCustomSummaryEventArgs.SummaryValue property and use them in custom summary calculations.
The CustomSummary event occurs when the control layout is not ready yet. It means that other cells, columns and rows are not accessible.
Tip
To include other cells in a custom cell value calculation, handle the CustomCellValue event.
Note
The CustomSummary event is not supported in server and OLAP mode.

Example
This example demonstrates how to count distinct values (the number of orders with equal product quantities) and display the result in the pivot grid.
This example handles the CustomSummary event that occurs when the control calculates a summary for a field whose SummaryType (see DevExpress.XtraPivotGrid.PivotGridFieldBase.SummaryType) is DevExpress.Data.PivotGrid.PivotSummaryType. The event handler calls the DevExpress.XtraPivotGrid.Data.PivotGridCustomSummaryEventArgsBase`1.CreateDrillDownDataSource method to retrieve the underlying data rows for the current cell, counts distinct values and returns the result to the DevExpress.XtraPivotGrid.Data.PivotGridCustomSummaryEventArgsBase`1.CustomValue property.

MainWindow.xaml |
<dx:ThemedWindow x:Class="DXPivotGrid_CustomSummary.MainWindow" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DXPivotGrid_CustomSummary"
xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid">
<Grid>
<dxpg:PivotGridControl CustomSummary="pivotGridControl1_CustomSummary" Loaded="PivotGridControl1_Loaded" Name="pivotGridControl1">
<dxpg:PivotGridControl.Fields>
<dxpg:PivotGridField Name="fieldCategoryName" FieldName="CategoryName" Area="RowArea" AreaIndex="0" Caption="Category Name" />
<dxpg:PivotGridField Name="fieldProductName" FieldName="ProductName" Area="RowArea" AreaIndex="1" Caption="Product Name" />
<dxpg:PivotGridField Name="fieldOrderDate" FieldName="OrderDate" Area="ColumnArea" AreaIndex="0" Caption="OrderDate" GroupInterval="DateYear" />
<dxpg:PivotGridField Name="fieldQuantity" FieldName="Quantity" Area="DataArea" AreaIndex="0" Caption="Quantity" />
<dxpg:PivotGridField Name="fieldQuantityDistinctCount" FieldName="Quantity" Area="DataArea" AreaIndex="1" Caption="Count Distinct" SummaryType="Custom" />
</dxpg:PivotGridControl.Fields>
</dxpg:PivotGridControl>
</Grid>
</dx:ThemedWindow>
|
MainWindow.xaml.vb |
Imports DevExpress.DataAccess.Excel
Imports System
Imports System.Collections
Imports System.Windows
Namespace DXPivotGrid_CustomSummary
''' <summary>
''' Interaction logic for MainWindow.xaml
''' </summary>
Partial Public Class MainWindow
Inherits DevExpress.Xpf.Core.ThemedWindow
Private ds As New ExcelDataSource()
Public Sub New()
InitializeComponent()
ds.Name = "Excel Data Source"
ds.FileName = "SalesPerson.xlsx"
Dim worksheetSettings As New ExcelWorksheetSettings("Data")
ds.SourceOptions = New ExcelSourceOptions(worksheetSettings)
ds.Fill()
pivotGridControl1.DataSource = ds
End Sub
Private Sub pivotGridControl1_CustomSummary(ByVal sender As Object, ByVal e As DevExpress.Xpf.PivotGrid.PivotCustomSummaryEventArgs)
Dim name_Renamed As String = e.DataField.FieldName
Dim list As IList = e.CreateDrillDownDataSource()
Dim ht As New Hashtable()
For i As Integer = 0 To list.Count - 1
Dim row As DevExpress.XtraPivotGrid.PivotDrillDownDataRow = TryCast(list(i), DevExpress.XtraPivotGrid.PivotDrillDownDataRow)
Dim v As Object = row(name_Renamed)
If v IsNot Nothing AndAlso v IsNot DBNull.Value Then
ht(v) = Nothing
End If
Next i
e.CustomValue = ht.Count
End Sub
Private Sub PivotGridControl1_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
pivotGridControl1.BestFit()
End Sub
End Class
End Namespace
|
MainWindow.xaml.cs |
using DevExpress.DataAccess.Excel;
using System;
using System.Collections;
using System.Windows;
namespace DXPivotGrid_CustomSummary
{
public partial class MainWindow : DevExpress.Xpf.Core.ThemedWindow
{
ExcelDataSource ds = new ExcelDataSource();
public MainWindow()
{
InitializeComponent();
ds.Name = "Excel Data Source";
ds.FileName = "SalesPerson.xlsx";
ExcelWorksheetSettings worksheetSettings = new ExcelWorksheetSettings("Data");
ds.SourceOptions = new ExcelSourceOptions(worksheetSettings);
ds.Fill();
pivotGridControl1.DataSource = ds;
}
private void pivotGridControl1_CustomSummary(object sender, DevExpress.Xpf.PivotGrid.PivotCustomSummaryEventArgs e)
{
string name = e.DataField.FieldName;
IList list = e.CreateDrillDownDataSource();
Hashtable ht = new Hashtable();
for (int i = 0; i < list.Count; i++)
{
DevExpress.XtraPivotGrid.PivotDrillDownDataRow row = list[i] as DevExpress.XtraPivotGrid.PivotDrillDownDataRow;
object v = row[name];
if (v != null && v != DBNull.Value)
ht[v] = null;
}
e.CustomValue = ht.Count;
}
private void PivotGridControl1_Loaded(object sender, RoutedEventArgs e)
{
pivotGridControl1.BestFit();
}
}
}
|