Skip to main content
A newer version of this page is available. .

XRPivotGrid.DataSource Property

Gets or sets the pivot grid control’s data source. If it’s empty, then the report’s data source will be used.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v19.1.dll

NuGet Packages: DevExpress.Reporting.Core, DevExpress.WindowsDesktop.Core

Declaration

[SRCategory(ReportStringId.CatData)]
public object DataSource { get; set; }

Property Value

Type Description
Object

A Object representing the pivot grid control’s data source.

Remarks

Objects such as a DataTable, a DataView, an IList, an IListSource and an IBindingList can be used as data sources.

Note

If the data source isn’t set for the XRPivotGrid control (the DataSource property is set to null), then the data source will be obtained from the XtraReportBase.DataSource property of the report which contains this XRPivotGrid control.

Example

The following code generates a cross-tab report by utilizing the XRPivotGrid control.

Before running this code, add all necessary assemblies to the project’s References list (e.g., DevExpress.XtraPivotGrid.v19.1.dll and DevExpress.PivotGrid.v19.1.Core.dll).

Next, add a button (button1) to the application’s form and handle its Click event as follows.

using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Sql;
using DevExpress.XtraPivotGrid;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.UI.PivotGrid;
// ...
private void button1_Click(object sender, EventArgs e) {
    // Create a cross-tab report.
    XtraReport report = CreateReport();

    // Show its Print Preview.
    report.ShowPreview();
}

private XtraReport CreateReport() {
    // Create a blank report.
    XtraReport crossTabReport = new XtraReport();

    // Create a detail band and add it to the report.
    DetailBand detail = new DetailBand();
    crossTabReport.Bands.Add(detail);

    // Create a pivot grid and add it to the Detail band.
    XRPivotGrid pivotGrid = new XRPivotGrid();
    detail.Controls.Add(pivotGrid);

    // Create a data source
    Access97ConnectionParameters connectionParameters = new Access97ConnectionParameters("..\\..\\nwind.mdb", "", "");
    SqlDataSource ds = new SqlDataSource(connectionParameters);

    // Create an SQL query to access the SalesPerson view.
    CustomSqlQuery query = new CustomSqlQuery();
    query.Name = "SalesPerson";
    query.Sql = "SELECT CategoryName, ProductName, Country, [Sales Person], Quantity, [Extended Price]  FROM SalesPerson";
    ds.Queries.Add(query);

    // Bind the pivot grid to data.
    pivotGrid.DataSource = ds;
    pivotGrid.DataMember = "SalesPerson";

    // Generate pivot grid's fields.
    XRPivotGridField fieldCategoryName = new XRPivotGridField("CategoryName", PivotArea.RowArea);
    XRPivotGridField fieldProductName = new XRPivotGridField("ProductName", PivotArea.RowArea);
    XRPivotGridField fieldCountry = new XRPivotGridField("Country", PivotArea.ColumnArea);
    XRPivotGridField fieldSalesPerson = new XRPivotGridField("Sales Person", PivotArea.ColumnArea);
    XRPivotGridField fieldQuantity = new XRPivotGridField("Quantity", PivotArea.DataArea);
    XRPivotGridField fieldExtendedPrice = new XRPivotGridField("Extended Price", PivotArea.DataArea);

    // Add these fields to the pivot grid.
    pivotGrid.Fields.AddRange(new XRPivotGridField[] {fieldCategoryName, fieldProductName, fieldCountry, 
        fieldSalesPerson, fieldQuantity, fieldExtendedPrice});

    return crossTabReport;
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the DataSource property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

Implements

DevExpress.Data.IDataContainerBase.DataSource
See Also