PivotGridCustomTotal Class
Represents a custom total which can be calculated for an outer column field or row field.
Namespace: DevExpress.XtraPivotGrid
Assembly: DevExpress.XtraPivotGrid.v24.2.dll
Declaration
Related API Members
The following members return PivotGridCustomTotal objects:
Remarks
The PivotGrid control supports automatic and custom Totals. An automatic total is calculated against a data field using a summary function which is determined by the field’s PivotGridFieldBase.SummaryType property.
A custom total allows you to calculate a total using a different summary function type. Moreover it’s possible to calculate multiple custom totals for a single data field.
Totals are displayed as additional rows or columns for each value in an outer column field or row field. To display custom totals for a column/row field, do the following:
- add PivotGridCustomTotal objects which represent custom totals to the field’s PivotGridField.CustomTotals collection
- set the field’s PivotGridFieldBase.TotalsVisibility property to PivotTotalsVisibility.CustomTotals
When a sequence of operations is performed each of which affects the control’s appearance, the PivotGrid control updates itself after each such operation. To prevent excessive updates you should enclose the code within calls to the PivotGridControl.BeginUpdate and PivotGridControl.EndUpdate methods. For instance, when setting custom totals for a field via code you can enclose the code within the BeginUpdate and EndUpdate method calls. In this case, the control will be updated only once - by the EndUpdate method.
Example
In the following example, four custom totals are added for a ‘Category Name’ row field. They will calculate the total Average, Sum, Min and Max values against the currently displayed data field.
The result is shown below.
using DevExpress.Data.PivotGrid;
using DevExpress.XtraPivotGrid;
// Get a reference to the CategoryName field.
PivotGridField field = pivotGridControl1.Fields["CategoryName"];
pivotGridControl1.BeginUpdate();
try {
// Clear the custom total collection.
field.CustomTotals.Clear();
// Add four items to the custom total collection to calculate the Average,
// Sum, Max and Min summaries.
field.CustomTotals.Add(PivotSummaryType.Average);
field.CustomTotals.Add(PivotSummaryType.Sum);
field.CustomTotals.Add(PivotSummaryType.Max);
field.CustomTotals.Add(PivotSummaryType.Min);
// Make the custom totals visible for this field.
field.TotalsVisibility = PivotTotalsVisibility.CustomTotals;
}
finally {
pivotGridControl1.EndUpdate();
}