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

XRPivotGrid Class

Displays multi-dimensional data in reports.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v19.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

public class XRPivotGrid :
    XRControl,
    IDataContainer,
    IDataContainerBase,
    IDataContainerBase2,
    IPivotGridEventsImplementorBase,
    IPivotGridPrinterOwner,
    IPrintable,
    IBasePrintable,
    IComponentLoading,
    IBindingList,
    IList,
    ICollection,
    IEnumerable,
    ITypedList,
    IPivotGrid,
    IChartDataSource,
    IPivotGridDataContainer,
    IPivotGridDataContainerCore,
    IXtraSerializableLayoutEx,
    IXtraSupportDeserializeCollection,
    IComplexControl

Remarks

The XRPivotGrid control duplicates all the general functionality of the PivotGridControl and allows you to display a pivot table in a report.

Display in the Toolbox

Starting with v19.2, the XRPivotGrid control is not available in the Toolbox. We recommend that you try the new XRCrossTab control instead.

The XRPivotGrid control is configured via the separate Designer outside the report context and requires that you write code in many popular scenarios.

The XRCrossTab control resolves certain XRPivotGrid‘s limitations and introduces the following design-time capabilities:

  • define a cross-tab layout right on the report surface without invoking a separate designer window;
  • access the most frequently used properties in smart tags;
  • use expression bindings to calculate and conditionally format any cell value;
  • filter data based on report parameter values;
  • specify odd and even styles;
  • customize appearance settings and assign styles for every visual element individually;
  • rotate the cell text (for instance, make vertical headers);
  • enable automatic column width calculation;
  • customize the text in the top left corner;
  • hide individual totals, headers, and any columns/rows.

Tip

See the Convert to the Cross Tab Control section for information on how to migrate your XRPivotGrid control.

If you still want to use the XRPivotGrid control and display it in the Toolbox instead of the XRCrossTab control, invoke the Report Designer Options dialog and set the DefaultCrossTabControl option to XRPivotGrid.

Add to Report and Bind to Data

  1. Open a report and drop the XRPivotGrid control from the Toolbox onto the report’s Detail band.

    HowTo_CrossTab

    You cannot place a Pivot Grid in another report control (for instance, XRTableCell or XRPanel) because its width cannot be determined at design time.

  2. Click the created control’s smart tag, expand the XRPivotGrid.DataSource property’s drop-down list and click Add Report Data Source.

    HowTo_CrossTab_0

  3. Follow the steps in the invoked Data Source Wizard to bind the Pivot Grid to data. For instance, bind to the Northwind database’s SalesPerson view. You can use the nwind.mdb file from the XtraReports installation (the default path is C:\Users\Public\Public Documents\DevExpress Demos 19.2\Components\Data\nwind.mdb).

    HowTo_CrossTab_1

Note

Ensure that a report’s XtraReportBase.DataSource property is not set if you place the Pivot Grid in the Detail band. Otherwise, the Pivot Grid data is printed as many times as there are rows in the report data source.

Define the Layout

  1. Click the control’s smart tag and select Run Designer in the invoked actions list.

    HowTo_CrossTab_2

  2. In the Pivot Grid Designer’s Fields page, click the Retrieve Fields button to obtain fields from the control’s data source.

    HowTo_CrossTab_3

  3. Switch to the Layout page in the navigation bar on the left and drag-and-drop data fields onto the appropriate areas to define the Pivot Grid’s layout. For instance, you can drag and drop the following fields:

    • the CategoryName and ProductName fields onto the Row Fields area;
    • the Country and SalesPerson fields onto the Column Fields area;
    • the ExtendedPrice field onto the Data Items area.

    HowTo_CrossTab_5

    Click Apply to apply the changes and close the Designer.

Tip

To see how the Pivot Grid looks when it is populated with data, switch to the report’s Preview.

Return to the Report Designer and invoke the Pivot Grid Designer. The pivot grid fields are now populated with actual data, and you can customize the grid.

Adjust the Layout Settings

Set the report’s XtraReport.VerticalContentSplitting property to Smart to split the Pivot Grid along the column borders if it does not fit the report’s page in Print Preview.

HowTo_CrossTab_2a

You can adjust a column’s width to fit its content. To do this, handle the Pivot Grid’s XRControl.BeforePrint event and call the XRPivotGridField.BestFit method at runtime. You can also use the XRPivotGrid.BestFit method to resize all the columns that correspond to the data and row fields to display all their content.

using System.Drawing.Printing;
// ...

private void xrPivotGrid1_BeforePrint(object sender, PrintEventArgs e) {
    xrPivotGrid1.BestFit(fieldProductName1);
}

Specify Print Options

Use the XRPivotGrid.OptionsPrint property to specify print options and define which Pivot Grid elements are printed.

cross-tab-report-options-print

You can now preview the report. Swicth to the Preview tab in Visual Studio.

HowTo_CrossTab_6

Use More Options

Refer to the WinForms Pivot Grid documentation for more information about the core Pivot Grid functionality.

See Pivot Charting (Integration with a Pivot Grid Control) for information on how to use a Pivot Grid as a Chart’s data source.

Convert to the Cross Tab Control

To migrate an existing Pivot Grid control to a new Cross Tab control, click the Pivot Grid’s smart tag and select Convert to Cross Tab.

Note that the Cross Tab does not support specific Pivot Grid functionality:

  • The Cross Tab cells cannot display pictures (both static and dynamic);
  • The Chart control cannot use the Cross Tab as a data source;
  • The Cross Tab does not support data headers that are used to manage location of data field headers;
  • The Cross Tab does not support the Pivot Grid’s predefined aggregate functions.

If the conversion result does not suit your requirements, you can restore the Pivot Grid. Click the Cross Tab’s smart tag and select Revert to Original Pivot Grid.

Implements

Show 23 items
DevExpress.XtraPrinting.IBrickOwner
DevExpress.Utils.Serializing.Helpers.IXtraSupportDeserializeCollectionItem
DevExpress.Utils.Serializing.IXtraSerializable
DevExpress.Data.IDataContainerBase
DevExpress.Data.IDataContainerBase2
DevExpress.XtraPivotGrid.Data.IPivotGridEventsImplementorBase
DevExpress.PivotGrid.Printing.IPivotGridPrinterOwner
DevExpress.Utils.IComponentLoading
DevExpress.Data.ChartDataSources.IPivotGrid
DevExpress.Data.ChartDataSources.IChartDataSource
DevExpress.Data.PivotGrid.IPivotGridDataContainerCore
DevExpress.Utils.Serializing.IXtraSerializableLayoutEx
DevExpress.Utils.Serializing.Helpers.IXtraSupportDeserializeCollection
See Also