windowsforms-1935-controls-and-libraries-pivot-grid-data-shaping-summarization-summaries-summary-display-modes.md
Summaries in cells are calculated according to the SummaryType property of data fields.
PivotGridControl can show how cell values correlate to summary values in other cells instead of displaying raw summary results. For instance, the Pivot Grid allows you to display the percentage of totals and grand totals, or the absolute or percentage difference between current and preceding cells.
You can implement the summary display type functionality through window calculations in Optimized mode. For this use the following classes:
Refer to the following topic for more information: Bind Pivot Grid Fields to Window Calculations.
You can also implement custom summaries to build an expression that executes complex calculations for a Pivot Grid field.
View Example: Pivot Grid for WinForms - How to Change SummaryDisplayType in the Context Menu
The following code snippet shows how to calculate different types of a percentage of all values for the Number field:
void ItemClick(object sender, EventArgs e) {
// ...
PivotGridField field = item.Tag as PivotGridField;
DataSourceColumnBinding sourceBinding = new DataSourceColumnBinding("Number");
PivotSummaryDisplayType newValue = (PivotSummaryDisplayType)Enum.Parse(typeof(PivotSummaryDisplayType), item.Caption);
switch(newValue) {
// ...
case PivotSummaryDisplayType.PercentOfColumn:
field.DataBinding = new PercentOfTotalBinding(
sourceBinding,
CalculationPartitioningCriteria.ColumnValueAndRowParentValue);
break;
case PivotSummaryDisplayType.PercentOfRow:
field.DataBinding = new PercentOfTotalBinding(
sourceBinding,
CalculationPartitioningCriteria.RowValueAndColumnParentValue);
break;
case PivotSummaryDisplayType.PercentOfColumnGrandTotal:
field.DataBinding = new PercentOfTotalBinding(
sourceBinding,
CalculationPartitioningCriteria.ColumnValue);
break;
case PivotSummaryDisplayType.PercentOfRowGrandTotal:
field.DataBinding = new PercentOfTotalBinding(
sourceBinding,
CalculationPartitioningCriteria.RowValue);
break;
case PivotSummaryDisplayType.PercentOfGrandTotal:
field.DataBinding = new PercentOfTotalBinding(
sourceBinding,
CalculationPartitioningCriteria.None);
break;
// ...
default:
field.DataBinding = sourceBinding;
break;
}
field.Tag = newValue;
}
Private Sub ItemClick(ByVal sender As Object, ByVal e As EventArgs)
' ...
Dim field As PivotGridField = TryCast(item.Tag, PivotGridField)
Dim sourceBinding As New DataSourceColumnBinding("Number")
Dim newValue As PivotSummaryDisplayType = DirectCast(System.Enum.Parse(GetType(PivotSummaryDisplayType), item.Caption), PivotSummaryDisplayType)
Select Case newValue
' ...
Case PivotSummaryDisplayType.PercentOfColumn
field.DataBinding = New PercentOfTotalBinding(sourceBinding, CalculationPartitioningCriteria.ColumnValueAndRowParentValue)
Case PivotSummaryDisplayType.PercentOfRow
field.DataBinding = New PercentOfTotalBinding(sourceBinding, CalculationPartitioningCriteria.RowValueAndColumnParentValue)
Case PivotSummaryDisplayType.PercentOfColumnGrandTotal
field.DataBinding = New PercentOfTotalBinding(sourceBinding, CalculationPartitioningCriteria.ColumnValue)
Case PivotSummaryDisplayType.PercentOfRowGrandTotal
field.DataBinding = New PercentOfTotalBinding(sourceBinding, CalculationPartitioningCriteria.RowValue)
Case PivotSummaryDisplayType.PercentOfGrandTotal
field.DataBinding = New PercentOfTotalBinding(sourceBinding, CalculationPartitioningCriteria.None)
' ...
Case Else
field.DataBinding = sourceBinding
End Select
field.Tag = newValue
End Sub
A data field’s PivotGridFieldBase.SummaryDisplayType property allows you to choose one of the predefined summary display types. The default value of this property (PivotSummaryDisplayType.Default) indicates that summary values are displayed as is.
See the following topics for more information about predefined summary display types:
See Also