Skip to main content

DataSourceColumnBinding Class

Defines a data binding to a source data column.

Namespace: DevExpress.XtraPivotGrid

Assembly: DevExpress.XtraPivotGrid.v22.1.dll

NuGet Package: DevExpress.Win.PivotGrid

Declaration

public class DataSourceColumnBinding :
    DataSourceColumnBindingBase

Remarks

Pivot Grid uses the Binding API to bind Pivot Grid’s fields to data. DataSourceColumnBinding allows you to bind a Pivot Grid’s field to a data column in the data source. The Pivot Grid’s field obtains its values from a field in the data source.

You can use DataSourceColumnBinding in Optimized, Server, and OLAP data processing modes.

Examples

Optimized and Server Modes

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

OLAP Mode

Follow the steps below to bind a Pivot Grid’s field to a measure or dimension in code in OLAP mode:

  1. Create a DataSourceColumnBinding instance.

  2. Specify the DataSourceColumnBindingBase.ColumnName property. ColumnName must specify the full name of the bound measure or dimension.

    For dimensions, the full name is composed of a dimension name, followed by a hierarchy name, followed by the name of a level(s). All names should be wrapped within square brackets and separated from one another with the dot symbol. Example: “[Customer].[Customer Geography].[Country]”.

    For measures, the full name is composed of the “[Measures].” string followed by the measure name. Example: “[Measures].[Sales Amount]”.

  3. Assign the DataSourceColumnBinding object to the PivotGridFieldBase.DataBinding property.

The following code snippet illustrates how to create the fieldCity field and bind it to the City dimension:

PivotGridField fieldCity = pivotGridControl1.Fields.Add("City", PivotArea.RowArea);
fieldCity.DataBinding = new DataSourceColumnBinding("[Customer].[City].[City]");
fieldCity.Name = "fieldCity";

View Example: How to Connect a Pivot Grid to an OLAP Data Source

Inheritance

See Also