PivotGridControl Class
Namespace: DevExpress.Xpf.PivotGrid
Assembly:
DevExpress.Xpf.PivotGrid.v21.1.dll
NuGet Package:
DevExpress.Wpf.PivotGrid
Declaration
[OLAPDataAccessMetadata("All", SupportedProcessingModes = "Pivot", OLAPConnectionStringProperty = "OlapConnectionString", OLAPDataProviderProperty = "OlapDataProvider", DataSourceProperty = "DataSource")]
public class PivotGridControl :
Control,
IPrintableControl,
IFormatsOwner,
INotifyPropertyChanged,
IPivotGridEventsImplementor,
IPivotGridEventsImplementorBase,
ILogicalOwner,
IInputElement,
IWeakEventListener,
ISupportInitialize,
IFormatConditionCollectionOwner,
IThreadSafeAccessible
<OLAPDataAccessMetadata("All", SupportedProcessingModes:="Pivot", OLAPConnectionStringProperty:="OlapConnectionString", OLAPDataProviderProperty:="OlapDataProvider", DataSourceProperty:="DataSource")>
Public Class PivotGridControl
Inherits Control
Implements IPrintableControl,
IFormatsOwner,
INotifyPropertyChanged,
IPivotGridEventsImplementor,
IPivotGridEventsImplementorBase,
ILogicalOwner,
IInputElement,
IWeakEventListener,
ISupportInitialize,
IFormatConditionCollectionOwner,
IThreadSafeAccessible
The following members return PivotGridControl objects:
The PivotGridControl represents data from a data source in cross-tab form. It calculates summaries and summary totals against specific fields and displays the summary values within data cells. The following summary functions are supported: Sum, Average, Count, Min, Max, StdDev, StdDevp, StdVar, StdVarp.
Fields are basic blocks, representing data source fields, which an end-user can manipulate in the PivotGridControl. Fields are visually represented by field headers, which can be moved between the pivot grid’s areas using drag-and-drop. Dragging fields between areas allows you to reorganize the data and present it in various forms. The collection of fields can be accessed via the PivotGridControl.Fields property. Individual fields are represented by the PivotGridField class and can be accessed using indexed notation.
For detailed information on key features introduced by the DXPivotGrid, see:
Example
The following example demonstrates how to programmatically bind the PivotGridControl
to a “SalesPerson” view in the nwind.mdb database, which is shipped with the installation. The control will be used to analyse sales per country, customers, product categories and years.
First, data is obtained from an MDB database via the OleDbConnection, OleDbDataAdapter and DataSet components. Secondly, the PivotGridControl is bound to a table in the dataset via the PivotGridControl.DataSource property. Lastly, pivot grid fields are created that will represent datasource fields. They are positioned within appropriate areas to analyze the data in the way you want.
Note that if you want to see an example of how to add pivot grid fields in XAML, please refer to the How to: Bind a PivotGrid to an MS Access Database tutorial.
View Example
<Window x:Class="HowToBindToMDB.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Grid>
<dxpg:PivotGridControl Name="pivotGridControl1"
HorizontalAlignment="Left" VerticalAlignment="Top" />
</Grid>
</Window>
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Windows
Imports DevExpress.Xpf.PivotGrid
Namespace HowToBindToMDB
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Create a connection object.
Dim connection As _
New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND.MDB")
' Create a data adapter.
Dim adapter As _
New OleDbDataAdapter("SELECT * FROM SalesPerson", connection)
' Create and fill a dataset.
Dim sourceDataSet As New DataSet()
adapter.Fill(sourceDataSet, "SalesPerson")
' Assign the data source to the PivotGrid control.
pivotGridControl1.DataSource = sourceDataSet.Tables("SalesPerson")
pivotGridControl1.BeginUpdate()
' Create a row pivot grid field bound to the Country datasource field.
Dim fieldCountry As New PivotGridField("Country", FieldArea.RowArea)
' Create a row pivot grid field bound to the Sales Person datasource field.
Dim fieldCustomer As New PivotGridField("Sales Person", FieldArea.RowArea)
fieldCustomer.Caption = "Customer"
' Create a column pivot grid field bound to the OrderDate datasource field.
Dim fieldYear As New PivotGridField("OrderDate", FieldArea.ColumnArea)
fieldYear.Caption = "Year"
' Group field values by years.
fieldYear.GroupInterval = FieldGroupInterval.DateYear
' Create a column pivot grid field bound to the CategoryName datasource field.
Dim fieldCategoryName As New PivotGridField("CategoryName", FieldArea.ColumnArea)
fieldCategoryName.Caption = "Product Category"
' Create a filter pivot grid field bound to the ProductName datasource field.
Dim fieldProductName As New PivotGridField("ProductName", FieldArea.FilterArea)
fieldProductName.Caption = "Product Name"
' Create a data pivot grid field bound to the 'Extended Price' datasource field.
Dim fieldExtendedPrice As New PivotGridField("Extended Price", FieldArea.DataArea)
' Specify the formatting setting to format summary values as integer currency amount.
fieldExtendedPrice.CellFormat = "c0"
' Add the fields to the control's field collection.
pivotGridControl1.Fields.AddRange(fieldCountry, fieldCustomer, fieldCategoryName, _
fieldProductName, fieldYear, fieldExtendedPrice)
' Arrange the row fields within the Row Header Area.
fieldCountry.AreaIndex = 0
fieldCustomer.AreaIndex = 1
' Arrange the column fields within the Column Header Area.
fieldCategoryName.AreaIndex = 0
fieldYear.AreaIndex = 1
pivotGridControl1.EndUpdate()
End Sub
End Class
End Namespace
using System.Data;
using System.Data.OleDb;
using System.Windows;
using DevExpress.Xpf.PivotGrid;
namespace HowToBindToMDB {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e) {
// Create a connection object.
OleDbConnection connection =
new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND.MDB");
// Create a data adapter.
OleDbDataAdapter adapter =
new OleDbDataAdapter("SELECT * FROM SalesPerson", connection);
// Create and fill a dataset.
DataSet sourceDataSet = new DataSet();
adapter.Fill(sourceDataSet, "SalesPerson");
// Assign the data source to the PivotGrid control.
pivotGridControl1.DataSource = sourceDataSet.Tables["SalesPerson"];
pivotGridControl1.BeginUpdate();
// Create a row pivot grid field bound to the Country datasource field.
PivotGridField fieldCountry = new PivotGridField("Country", FieldArea.RowArea);
// Create a row pivot grid field bound to the Sales Person datasource field.
PivotGridField fieldCustomer = new PivotGridField("Sales Person", FieldArea.RowArea);
fieldCustomer.Caption = "Customer";
// Create a column pivot grid field bound to the OrderDate datasource field.
PivotGridField fieldYear = new PivotGridField("OrderDate", FieldArea.ColumnArea);
fieldYear.Caption = "Year";
// Group field values by years.
fieldYear.GroupInterval = FieldGroupInterval.DateYear;
// Create a column pivot grid field bound to the CategoryName datasource field.
PivotGridField fieldCategoryName = new PivotGridField("CategoryName", FieldArea.ColumnArea);
fieldCategoryName.Caption = "Product Category";
// Create a filter pivot grid field bound to the ProductName datasource field.
PivotGridField fieldProductName = new PivotGridField("ProductName", FieldArea.FilterArea);
fieldProductName.Caption = "Product Name";
// Create a data pivot grid field bound to the 'Extended Price' datasource field.
PivotGridField fieldExtendedPrice = new PivotGridField("Extended Price", FieldArea.DataArea);
// Specify the formatting setting to format summary values as integer currency amount.
fieldExtendedPrice.CellFormat = "c0";
// Add the fields to the control's field collection.
pivotGridControl1.Fields.AddRange(fieldCountry, fieldCustomer,
fieldCategoryName, fieldProductName, fieldYear, fieldExtendedPrice);
// Arrange the row fields within the Row Header Area.
fieldCountry.AreaIndex = 0;
fieldCustomer.AreaIndex = 1;
// Arrange the column fields within the Column Header Area.
fieldCategoryName.AreaIndex = 0;
fieldYear.AreaIndex = 1;
pivotGridControl1.EndUpdate();
}
}
}
The following code snippets (auto-collected from DevExpress Examples) contain references to the PivotGridControl class.
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.
See Also