Back to Devexpress

Bind Pivot Grid Fields to Data Columns

windowsforms-401376-controls-and-libraries-pivot-grid-binding-to-data-in-memory-mode-optimized-mode-bind-pivot-grid-fields-to-data-columns.md

latest3.2 KB
Original Source

Bind Pivot Grid Fields to Data Columns

  • Aug 05, 2022
  • 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:

  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:

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:

csharp
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);
vb
Dim fieldProductAmount As New PivotGridField()
fieldProductAmount.Area = PivotArea.DataArea
fieldProductAmount.Caption = "Product Sales"
fieldProductAmount.Name = "fProductAmount"

Dim productAmountBinding As 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

Bind Pivot Grid Fields to Calculated Expressions

PivotGridField

Pivot Grid Data Processing Modes

Bind Pivot Grid Fields to Window Calculations