windowsforms-401376-controls-and-libraries-pivot-grid-binding-to-data-in-memory-mode-optimized-mode-bind-pivot-grid-fields-to-data-columns.md
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.
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:
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:
Follow the steps below to bind a Pivot Grid’s field to the data source field in code:
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);
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