Bind Pivot Grid Fields to Window Calculations
- 2 minutes to read
The article describes how to use the Binding API to bind a Pivot Grid field to the result of the window calculation when the Pivot Grid uses the Optimized data processing engine.
Design Time
Add a new field to the data area in any of the following ways:
Click ‘Run Designer’ in the PivotGrid’s smart tag menu. In the Pivot Grid Designer window, select the Fields page and click or to add a new field.
Use the ‘Add Field to Data Area’ option in the PivotGrid’s smart tag. Then, you can specify its properties in the property grid or in the field’s smart tag menu.
Set the field’s PivotGridFieldBase.DataBinding property to one of the following values:
Specify calculation properties according to the set
DataBinding
value.For example, the image below illustrates settings specified for the Running Total binding:
Runtime
The following example shows how to create the RunningTotalBinding
calculation binding. The Pivot Grid binds the fieldProductAmountRunningTotal
field to the result of the running total calculation.
- Create an instance of the RunningTotalBinding class with the Source property set to the DataBindingBase descendant’s instance.
- Specify the window frame and summary type.
- Assign the RunningTotalBinding instance to the PivotGridField.DataBinding property.
pivotGridControl.OptionsData.DataProcessingEngine = PivotDataProcessingEngine.Optimized;
PivotGridField fieldProductAmount = new PivotGridField() {
Area = PivotArea.DataArea,
Caption = "Product Sales",
Name = "fProductAmount"
};
PivotGridField fieldProductAmountRunningTotal = new PivotGridField {
Area = PivotArea.DataArea,
Caption = "Running Total",
Name = "fRunningTotal"
};
DataSourceColumnBinding productAmountBinding = new DataSourceColumnBinding("ProductAmount");
//Bind a field to a column in the data source.
fieldProductAmount.DataBinding = productAmountBinding;
//Calculate a running summary on the column.
fieldProductAmountRunningTotal.DataBinding = new RunningTotalBinding() {
Source = productAmountBinding,
PartitioningCriteria = CalculationPartitioningCriteria.ColumnValue,
SummaryType = PivotSummaryType.Sum
};
pivotGridControl.Fields.AddRange(new PivotGridField[] {
fieldProductAmount,
fieldProductAmountRunningTotal,
});