Bind Pivot Grid Fields to Data Columns
- 2 minutes to read
This topic describes how to use the Binding API to bind a Pivot Grid field to a data source column when the Pivot Grid uses the Optimized data processing engine.
Design-Time
Follow the steps below to bind a Pivot Grid field to a data source column:
Add a new data field 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 one of the ‘Add Field to…’ options in the PivotGrid’s smart tag menu to add a new field to the required area directly. 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
Data Source Column
.Specify the source column in the DataSourceColumnBindingBase.ColumnName property. For example, the image below illustrates a Pivot Grid field that is bound to the Extended Price column:
Runtime
Follow the steps below to bind a Pivot Grid’s field to the data source field in code:
- Create a DataSourceColumnBinding instance.
- Set the DataSourceColumnBindingBase.ColumnName property to the name of the source data field.
- Assign the
DataSourceColumnBinding
object to the PivotGridFieldBase.DataBinding property.
The following code snippet illustrates how to create the Pivot Grid’s fieldProductAmount
field and bind it to the ProductAmount
source field:
PivotGridField fieldProductAmount = new PivotGridField() {
Area = PivotArea.DataArea,
Caption = "Product Sales",
Name = "fProductAmount"
};
DataSourceColumnBinding productAmountBinding = new DataSourceColumnBinding("ProductAmount");
//Bind a field to a column in the data source.
fieldProductAmount.DataBinding = productAmountBinding;
pivotGridControl.Fields.Add(fieldProductAmount);