Back to Devexpress

PivotGridControl.Fields Property

wpf-devexpress-dot-xpf-dot-pivotgrid-dot-pivotgridcontrol-b830d340.md

latest11.3 KB
Original Source

PivotGridControl.Fields Property

Provides access to a pivot grid’s field collection.

Namespace : DevExpress.Xpf.PivotGrid

Assembly : DevExpress.Xpf.PivotGrid.v25.2.dll

NuGet Package : DevExpress.Wpf.PivotGrid

Declaration

csharp
public PivotGridFieldCollection Fields { get; }
vb
Public ReadOnly Property Fields As PivotGridFieldCollection

Property Value

TypeDescription
PivotGridFieldCollection

A PivotGridFieldCollection object which represents a collection of all the fields within a pivot grid.

|

Remarks

The Fields collection stores all the fields contained in the PivotGridControl. It provides methods allowing you to access, add and delete fields. Individual fields can be accessed using indexed notation.

To learn more, see Fields.

Example

The following example demonstrates how to 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.

The following steps were used to created this example:

  1. A typed dataset is created from the database at design time.
  2. Instances of SalesPersonDataTable and SalesPersonTableAdapter objects are created.
  3. The PivotGridControl is bound to the SalesPersonDataTable instance via the PivotGridControl.DataSource property.
  4. The table is filled with data in the Window_Loaded event handler.

The pivot grid fields that will represent data source fields are created in XAML markup. 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 programmatically add pivot grid fields, please refer to the How to: Bind a PivotGrid to an MS Access Database Programmatically example.

xaml
<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" DataProcessingEngine="Optimized">
            <dxpg:PivotGridControl.Fields>
                <dxpg:PivotGridField Name="fieldCountry" Area="RowArea">
                    <dxpg:PivotGridField.DataBinding>
                        <dxpg:DataSourceColumnBinding ColumnName="Country"/>
                    </dxpg:PivotGridField.DataBinding>
                </dxpg:PivotGridField>
                <dxpg:PivotGridField Name="fieldCustomer" Area="RowArea"
                                     Caption="Customer">
                    <dxpg:PivotGridField.DataBinding>
                        <dxpg:DataSourceColumnBinding ColumnName="Sales Person"/>
                    </dxpg:PivotGridField.DataBinding>
                </dxpg:PivotGridField>
                <dxpg:PivotGridField Name="fieldYear" Area="ColumnArea" Caption="Year" >
                    <dxpg:PivotGridField.DataBinding>
                        <dxpg:DataSourceColumnBinding ColumnName="OrderDate" GroupInterval="DateYear"/>
                    </dxpg:PivotGridField.DataBinding>
                </dxpg:PivotGridField>
                <dxpg:PivotGridField Name="fieldCategoryName" Area="ColumnArea" Caption="Product Category">
                    <dxpg:PivotGridField.DataBinding>
                        <dxpg:DataSourceColumnBinding ColumnName="CategoryName"/>
                    </dxpg:PivotGridField.DataBinding>
                </dxpg:PivotGridField>
                <dxpg:PivotGridField Name="fieldProductName" Area="FilterArea" Caption="Product Name">
                    <dxpg:PivotGridField.DataBinding>
                        <dxpg:DataSourceColumnBinding ColumnName="ProductName"/>
                    </dxpg:PivotGridField.DataBinding>
                </dxpg:PivotGridField>
                <dxpg:PivotGridField Name="fieldExtendedPrice" Area="DataArea" CellFormat="c0">
                    <dxpg:PivotGridField.DataBinding>
                        <dxpg:DataSourceColumnBinding ColumnName="Extended Price"/>
                    </dxpg:PivotGridField.DataBinding>
                </dxpg:PivotGridField>
            </dxpg:PivotGridControl.Fields>
        </dxpg:PivotGridControl>
    </Grid>
</Window>
cs
using System.Data;
using System.Data.OleDb;
using System.Windows;
using DevExpress.Xpf.PivotGrid;
using HowToBindToMDB.NwindDataSetTableAdapters;

namespace HowToBindToMDB {
    public partial class MainWindow : Window {
        NwindDataSet.SalesPersonDataTable salesPersonDataTable = 
            new NwindDataSet.SalesPersonDataTable();
        SalesPersonTableAdapter salesPersonDataAdapter = new SalesPersonTableAdapter();

        public MainWindow() {
            InitializeComponent();
            pivotGridControl1.DataSource = salesPersonDataTable;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e) {
            salesPersonDataAdapter.Fill(salesPersonDataTable);
        }
    }
}
vb
Imports System.Windows
Imports HowToBindToMDB.NwindDataSetTableAdapters

Namespace HowToBindToMDB

    Public Partial Class MainWindow
        Inherits Window

        Private salesPersonDataTable As NwindDataSet.SalesPersonDataTable = New NwindDataSet.SalesPersonDataTable()

        Private salesPersonDataAdapter As SalesPersonTableAdapter = New SalesPersonTableAdapter()

        Public Sub New()
            Me.InitializeComponent()
            Me.pivotGridControl1.DataSource = salesPersonDataTable
        End Sub

        Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            salesPersonDataAdapter.Fill(salesPersonDataTable)
        End Sub
    End Class
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references to the Fields 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.

wpf-pivotgrid-how-to-display-underlying-data-asynchronously/CS/WpfDrillDownDataSourceExample/MainWindow.xaml#L33

xml
DataProcessingEngine="Optimized">
<dxpg:PivotGridControl.Fields>
    <dxpg:PivotGridField

wpf-pivot-grid-add-custom-field-values-rows-columns-not-present-in-datasource/CS/WpfApplication1/MainWindow.xaml#L17

xml
<dxpg:PivotGridControl x:Name="pivot" CustomFieldValueCells="pivot_CustomFieldValueCells" DataProcessingEngine="Optimized">
    <dxpg:PivotGridControl.Fields>
        <dxpg:PivotGridField Area="DataArea" Caption="Value">

wpf-pivot-grid-create-context-menu-for-field-values/CS/WpfPivotGrid_CustomMenu/MainWindow.xaml#L24

xml
<dxpg:PivotGridControl Name="pivotGrid" RowTreeWidth="130">
    <dxpg:PivotGridControl.Fields>
        <dxpg:PivotGridField Area="RowArea" FieldName="Name" />

wpf-pivot-grid-create-field-value-template/CS/HowToCreateFieldValueTemplate/MainWindow.xaml#L20

xml
<dxpg:PivotGridControl Name="pivotGridControl1" DataProcessingEngine="Optimized">
    <dxpg:PivotGridControl.Fields>
        <dxpg:PivotGridField Name="fieldCountry" Area="ColumnArea" >

wpf-pivotgrid-customize-the-cell-template/CS/HowToCustomizeCellTemplate/MainWindow.xaml#L9

xml
<dxpg:PivotGridControl x:Name="pivotGridControl1" DataProcessingEngine="Optimized">
    <dxpg:PivotGridControl.Fields>
        <dxpg:PivotGridField

wpf-pivot-grid-hide-specific-columns-and-row/CS/WpfApp/Data.cs#L28

csharp
pivot.Fields.AddDataSourceColumn(Remains, FieldArea.DataArea);
foreach (PivotGridField field in pivot.Fields) {
    field.AllowedAreas = GetAllowedArea(field.Area);

wpf-pivot-grid-split-field-value-cells/CS/Data.cs#L27

csharp
pivot.Fields.AddDataSourceColumn(Quantity, FieldArea.DataArea);
foreach (PivotGridField field in pivot.Fields) {
    field.AllowedAreas = GetAllowedArea(field.Area);

wpf-pivot-grid-hide-specific-columns-and-row/VB/WpfApp/Data.vb#L31

vb
pivot.Fields.AddDataSourceColumn(Remains, FieldArea.DataArea)
For Each field As PivotGridField In pivot.Fields
    field.AllowedAreas = GetAllowedArea(field.Area)

wpf-pivot-grid-split-field-value-cells/VB/Data.vb#L39

vb
pivot.Fields.AddDataSourceColumn(Quantity, FieldArea.DataArea)
For Each field As PivotGridField In pivot.Fields
    field.AllowedAreas = GetAllowedArea(field.Area)

See Also

PivotGridControl Class

PivotGridControl Members

DevExpress.Xpf.PivotGrid Namespace