Binding to Data Overview

  • 3 minutes to read

The PivotGridControl should be connected to an external data source that provides data you wish to display and process. You can bind a PivotGridControl to various types of data sources (an SQL database, an XML file, an OLAP cube, etc.).

To display data within the PivotGridControl, create Pivot Grid fields that are used to visualize data from specific data source fields.


The PivotGridControl is not automatically updated when the data source is modified. You need to call the PivotGridControl.RefreshData method that will forcibly recalculate summaries.

Bind a Pivot Grid to Data at Design Time

To bind the PivotGridControl to data, click its smart tag and select one of the following options.


Bind a Pivot Grid to Data in Code

The PivotGridControl exposes the PivotGridControl.DataSource property used to specify the data source for the Pivot Grid. The following topic lists typical data sources to which the data-aware DevExpress controls can be bound: Traditional Data Binding Methods.

To learn how to bind the PivotGridControl to various types of data sources in code, see examples from the Items Source Configuration Wizard section.

The following example demonstrates how to bind the PivotGridControl to a "SalesPerson" view in the nwind.mdb database, which is shipped with the installation. The control will be used to analyse sales per country, customers, product categories and years.

The following steps were used to created this example:

  1. A typed dataset is created from the database at design time.
  2. Instances of SalesPersonDataTable and SalesPersonTableAdapter objects are created.
  3. The PivotGridControl is bound to the SalesPersonDataTable instance via the PivotGridControl.DataSource property.
  4. The table is filled with data in the Window_Loaded event handler.

The pivot grid fields that will represent data source fields are created in XAML markup. They are positioned within appropriate areas to analyze the data in the way you want.

Note that if you want to see an example of how to programmatically add pivot grid fields, please refer to the How to: Bind a PivotGrid to an MS Access Database Programmatically tutorial.

<Window x:Class="HowToBindToMDB.MainWindow"
        Title="MainWindow" Height="350" Width="525"  Loaded="Window_Loaded">
        <dxpg:PivotGridControl HorizontalAlignment="Left" Name="pivotGridControl1"
                <dxpg:PivotGridField Name="fieldCountry" FieldName="Country" Area="RowArea" />
                <dxpg:PivotGridField Name="fieldCustomer" FieldName="Sales Person" Area="RowArea"
                                     Caption="Customer" />
                <dxpg:PivotGridField Name="fieldYear" FieldName="OrderDate" Area="ColumnArea"
                                     Caption="Year" GroupInterval="DateYear" />
                <dxpg:PivotGridField Name="fieldCategoryName" FieldName="CategoryName" 
                                     Area="ColumnArea" Caption="Product Category" />
                <dxpg:PivotGridField Name="fieldProductName" FieldName="ProductName" 
                                     Area="FilterArea" Caption="Product Name" />
                <dxpg:PivotGridField Name="fieldExtendedPrice" FieldName="Extended Price" 
                                     Area="DataArea" CellFormat="c0" />