Skip to main content

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:

  1. 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 AddNewFieldButton or InsertNewFieldButton 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.

  2. Set the field’s PivotGridFieldBase.DataBinding property to Data Source Column.

  3. 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:

    Bind a Pivot Grid Field to a Column

Runtime

Follow the steps below to bind a Pivot Grid’s field to the data source field in code:

  1. Create a DataSourceColumnBinding instance.
  2. Set the DataSourceColumnBindingBase.ColumnName property to the name of the source data field.
  3. 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);

Run Demo: Optimized Mode - Field Calculation Bindings module in the XtraPivotGrid MainDemo

See Also