[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Collapse]Pivot Grid
   [Collapse]Getting Started
     Lesson 1 - Bind a Pivot Grid to an MDB Database
     Lesson 2 - Bind a Pivot Grid to an OLAP Cube
     Training Videos
     Included Components
   [Expand]Fundamentals
   [Expand]Binding to Data
   [Expand]Data Shaping
   [Expand]Data Analysis
   [Expand]Layout
   [Expand]Printing and Exporting
   [Expand]End-User Interaction
   [Expand]Appearance
   [Expand]MVVM Enhancements
   [Expand]UI Elements
   [Expand]End-User Capabilities
   [Expand]Examples
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Lesson 1 - Bind a Pivot Grid to an MDB Database

This tutorial will teach you how to add the PivotGridControl to your WPF application, bind it to a data source and map its fields to appropriate fields from a database. For teaching purposes, this example will use the Microsoft Access database (.mdb), which is one of the many data providers to which this pivot grid can be bound.

To create a simple WPF application with a pivot grid, do the following.

Expanded Steps 1-5. Create a New Project and Add the PivotGridControl

  1. Run MS Visual Studio.
  2. Create a new WPF Application project.
  3. Add PivotGridControl to your project by dragging the PivotGridControl item from the DX.19.2: Data & Analytics toolbox tab.

  4. Right-click the pivot grid and choose the Layout ? Reset All option in the context menu. This will stretch the control to fill the whole window.

  5. After this, your XAML may look like the following:

Expanded Steps 6-15. Create Data Objects

To add a data source to a WPF Application, follow the steps below.

  1. Select the PivotGridControl and click the smart tag icon at the top right corner of the control. Click the Items Source Wizard to invoke the wizard.

  2. Select the ADO.NET Typed DataSet data access technology and click the New Data Source... button.

  3. A message box that notifies you of the necessity to rebuild the solution and reopen the Items Source Configuration Wizard appears. Click Ok to run the Data Source Configuration Wizard.

  4. Choose Database as the type of data source.

  5. Then, choose Dataset as the Database Model.

  6. On the Choose Your Data Connection page, click New Connection... to create a connection to a database.

    The Add Connection dialog will be invoked.

  7. Specify the Microsoft Access Database File as your data source. Then, select the nwind.mdb database as your data connection. By default, it is stored in the following path.

    C:\Users\Public\Documents\DevExpress Demos 19.2\Components\Data

    Click OK to close the dialog and then click Next in the wizard.

  8. A message box that asks whether to copy the database file to the project appears. Click Yes.

  9. In the next step, you can choose whether to save the connection settings to a connection string or not.

    Make sure that the Yes, save the connection as check box is checked and click Next.

  10. In the Database Objects menu, choose the database columns that you need to include in the data source.

    To do this, expand the Views and SalesPerson nodes and select the following columns in the SalesPerson view.

    • Country;
    • ProductName;
    • CategoryName;
    • Extended Price;
    • Sales Person.

    After this, click Finish to close the wizard.

Expanded Steps 16-18. Bind the PivotGridControl to a Data Source/Specify Pivot Grid Data Source

To bind the PivotGridControl to a data source, follow the steps below.

  1. Rebuild the solution and reopen the Items Source Configuration Wizard. The newly created data source will be displayed within the Data Sources section.

  2. Select Simple Binding to bind the control to a plain collection of data objects and click Next.

    This will enable collections to have current record management functionalities, custom sorting, filtering, and grouping, select Manipulating Data via ICollectionView.

  3. Select the SalesPerson table and click Finish.

Expanded Step 19. Create Pivot Grid Fields and Bind Them to Database Fields

  1. Click the pivot grid's smart tag icon and then click Retrieve Fields in the popup window.

    The Pivot Grid control will create fields for all columns in the data source and locate the created fields in the Filter Header Area.

  2. Put the Country and Sales Person fields into the Column Header Area, the CategoryName and ProductName fields into the Row Header Area, and the Extended Price field into the Data Header Area.

    You can drag fields between areas and change their order within areas using drag-and-drop.

    After you have finished, the pivot grid fields should be arranged as illustrated below.

Expanded Result

Run the project and see the result.

Expanded See Also

Is this topic helpful?​​​​​​​