Tutorial 1 - Add the Pivot Grid and Bind It to Data
- 3 minutes to read
The following tutorial explains how to add the Pivot Grid to a WinForms application and connect the control to the Northwind SQLite Database.
Prerequisites
- A DevExpress Subscription that includes the WinForms Pivot Grid Control: WinForms Subscription, DXperience Subscription, or Universal Subscription.
The Northwind database. You can find the database file in the source-code example or in the following path (the database ships with the DevExpress installation package):
C:\Users\Public\Public Documents\DevExpress Demos 22.1\Components\Data\nwind.db
Visual Studio. Version 2022 is used in this tutorial.
Create a New Project and Add a Pivot Grid
Run Microsoft Visual Studio and create a new Windows Forms App (.NET Framework) project.
Specify the project’s name and location in the New Project wizard.
Drag the PivotGridControl item from the DX.24.1: Data & Analytics toolbox group onto the form.
Open the Pivot Grid’s smart tag menu and click Dock in Parent Container to let the Pivot Grid fill the entire window’s client area.
Add the Database to the Project
Add the Northwind Database to the project. For example, create the “Data” folder in your project and place the nwind.db file in the folder.
Install the System.Data.SQLite NuGet Package
In the Visual Studio menu, click Tools - NuGet Package Manager - Manage NuGet Packages for a Solution. In the invoked window, select the System.Data.SQLite package and click Install.
Connect the Pivot Grid to the Database in the Data Source Wizard
Click the Data Source Wizard panel.
In the invoked wizard, select SQL Data Connection and click New Data Source….
Click OK to create a new data source.
Configure the data connection
On the next page, select “No, I’d like to specify the connection parameters myself” to create a new data connection. Click Next.
Specify connection parameters. Choose SQLite as a data provider and specify a path to the Northwind database. Click Next to continue.
Click Next on the next page to save the connection string to the configuration file.
Specify a Query
Click Run Query Builder… to invoke the Query Builder dialog.
Drag the SalesPerson table and drop it on the diagram pane. Select the following table fields to include them in the query:
- ProductName
- CategoryName
- OrderDate
- ExtendedPrice
Click OK. The resulting query is displayed in the wizard.
Click Finish to create the data source.
Result
As a result, Visual Studio generates an SqlDataSource instance that supplies data from the Northwind database to the Pivot Grid control.
The sqlDataSource1
component is an SqlDataSource instance (a collection of tables, relationships, and constraints) that contains tables from the Northwind database.
Related Documentation
The following help topic contains information about the functionality used in the tutorial: Bind to Data.
Next Step
In the next tutorial, you create Pivot Grid fields, populate them with data, and configure the Pivot Grid layout.
Tutorial 2 - Populate Pivot Grid Fields with Data and Configure Layout