XRPivotGrid.Fields Property

Provides access to a pivot grid's field collection.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v20.2.dll


public XRPivotGridFieldCollection Fields { get; }

Property Value

Type Description

An XRPivotGridFieldCollection object which represents a collection of all the fields within a pivot grid.


This property stores all the fields present in the XRPivotGridcontrol. It allows you to add and delete fields using the appropriate methods.

Individual fields can be accessed using indexed notation or the bound field name as parameters. If the bound field name is used as an indexer and there are several fields with the same name (for example, the GroupInterval feature is used), the first field found in the collection will be returned.


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.v20.2.dll and DevExpress.PivotGrid.v20.2.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.

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();

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

    // 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";

    // 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;
See Also