PivotGridField Class

A field within the PivotGridControl control.

Namespace: DevExpress.XtraPivotGrid

Assembly: DevExpress.XtraPivotGrid.v20.1.dll

Declaration

public class PivotGridField :
    PivotGridFieldBase,
    IPivotGridViewInfoDataOwner,
    ISupportLookAndFeel,
    ISupportDXSkinColorsEx,
    ISupportDXSkinColors
Public Class PivotGridField
    Inherits PivotGridFieldBase
    Implements IPivotGridViewInfoDataOwner,
               ISupportLookAndFeel,
               ISupportDXSkinColorsEx,
               ISupportDXSkinColors

Remarks

A PivotGridField object is a field in the Pivot Grid control.

A field can be located in one of following areas:

cdFieldsLocation1

Area Field Type PivotGridFieldBase.Area value
Column Header Area Column Field PivotArea.ColumnArea
Row Header Area Row Field PivotArea.RowArea
Data Area Data Field PivotArea.DataArea
Filter Header Area Filter Field PivotArea.FilterArea

The field's position within its area is specified by the PivotGridFieldBase.AreaIndex property.

Fields can be bound and unbound. Bound fields get their data from a data source field whose name equals the PivotDataField.Name property value. Data for unbound fields should be supplied manually - by handling the PivotGridControl.CustomUnboundFieldData event.

TIP

To obtain distinct field values which can be used to filter a Pivot Grid's data, call the PivotGridFieldBase.GetUniqueValues method. See the Filtering Overview topic for more information on Pivot Grid's data filtering.

Use the following methods to obtain field data:

Method Description
PivotGridFieldBase.GetUniqueValues Obtains an array of distinct field values from the underlying data source. This method is used to fill in field's Filter Editors.
PivotGridFieldBase.GetAvailableValues Obtains an array of distinct field values contained in the records which are left after applying filters to other fields.
PivotGridFieldBase.GetVisibleValues Obtains a collection of unique field values contained in the records displayed in the Pivot Grid. Thus, these records are left after applying a field's filter to the field's available values (values contained in the records which are left after applying filters to other fields).

Examples

This example demonstrates how to create the pivot grid fields in code and specify their location and format. The PivotGridControl's data source is the ExcelDataSource instance, created in code.

PivotGridControl-Fields-DataSource

using DevExpress.DataAccess.Excel;
using DevExpress.XtraEditors;
using DevExpress.XtraPivotGrid;
using System;

namespace WinFormsPivotGridDataFieldsExample
{
    public partial class Form1 : XtraForm
    {
        public Form1()
        {
            InitializeComponent();
            this.Load += Form1_Load;
            // Create the Excel Data Source.
            ExcelDataSource ds = new ExcelDataSource();
            ds.FileName = "SalesPerson.xlsx";
            ExcelWorksheetSettings settings = new ExcelWorksheetSettings("Data");
            ds.SourceOptions = new ExcelSourceOptions(settings);
            ds.Fill();
            // Set the pivot's data source.
            pivotGridControl1.DataSource = ds;
            // Create pivot grid fields.
            PivotGridField fieldCategoryName = new PivotGridField()
            {
                Area = PivotArea.RowArea,
                AreaIndex = 0,
                Caption = "Category Name",
                FieldName = "CategoryName"
            };
            PivotGridField fieldProductName = new PivotGridField()
            {
                Area = PivotArea.RowArea,
                AreaIndex = 1,
                Caption = "Product Name",
                FieldName = "ProductName"
            };
            PivotGridField fieldExtendedPrice = new PivotGridField()
            {
                Area = PivotArea.DataArea,
                AreaIndex = 0,
                Caption = "Extended Price",
                FieldName = "Extended Price",
            };
            // Specify the field format.
            fieldExtendedPrice.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
            fieldExtendedPrice.CellFormat.FormatString = "c2";

            PivotGridField fieldOrderDate1 = new PivotGridField()
            {
                Area = PivotArea.ColumnArea,
                AreaIndex = 0,
                Caption = "Year",
                GroupInterval = PivotGroupInterval.DateYear,
                FieldName = "OrderDate",
            };
            PivotGridField fieldOrderDate2 = new PivotGridField()
            {
                Area = PivotArea.ColumnArea,
                AreaIndex = 1,
                Caption = "Quarter",
                GroupInterval = PivotGroupInterval.DateQuarter,
                FieldName = "OrderDate"
            };
            PivotGridField fieldCountry = new PivotGridField()
            {
                AreaIndex = 0,
                Caption = "Country",
                FieldName = "Country"
            };
            // Create a field's filter.
            fieldCountry.FilterValues.Clear();
            fieldCountry.FilterValues.FilterType = PivotFilterType.Included;
            fieldCountry.FilterValues.Add("USA");
            // Add fields to the pivot grid.
            pivotGridControl1.Fields.AddRange(new PivotGridField[] {
            fieldCategoryName,
            fieldProductName,
            fieldOrderDate1,
            fieldOrderDate2,
            fieldExtendedPrice,
            fieldCountry});
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            pivotGridControl1.BestFit();
        }
    }
}
See Also