Skip to main content

PivotGridControl.RetrieveFields(FieldArea, Boolean) Method

Creates PivotGridField objects for all fields in a data source, and moves them to the specified area, making them visible or hidden.

Namespace: DevExpress.Xpf.PivotGrid

Assembly: DevExpress.Xpf.PivotGrid.v24.1.dll

NuGet Package: DevExpress.Wpf.PivotGrid

Declaration

public void RetrieveFields(
    FieldArea area,
    bool visible
)

Parameters

Name Type Description
area FieldArea

A FieldArea enumeration value that specifies the area to which the created fields are moved.

visible Boolean

true to show the created fields; otherwise, false.

Remarks

This method clears the field collection and adds new PivotGridField objects to the collection for all columns in the control’s bound data source. This overload moves the created fields to the area according to the area parameter. The visible parameter specifies whether these fields are made visible or hidden.

The RetrieveFields method generates DataSourceColumnBinding objects for each Pivot Grid field in OLAP, Server, and Optimized modes. The Pivot Grid fields obtain their values from columns in the data source. The DataSourceColumnBinding.ColumnName property is set to the name of the data source column. The created fields are made visible and displayed within the Filter Header Area.

Use the PivotGridControl.Fields property to add or remove fields. For instance, you can add a calculated field to a collection that contains arbitrary data in the Pivot Grid control. Refer to the following topic for more information about calculated fields: Bind Pivot Grid Fields to Calculated Expressions.

Use the PivotGridControl.RetrieveFieldsAsync method to create fields asynchronously.

Specify a value of the PivotGridField.Name property for each field when you create Pivot Grid fields. You can use this value to determine fields in a stored layout.

Refer to the following topic for more information about Pivot Grid Fields: Pivot Grid Fields.

Example

The following example shows how to connect the Pivot Grid control to an OLAP Data Source and create Pivot Grid fields that are bound to OLAP measures and dimensions.

View Example

<Window xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"  x:Class="WpfOlapRetrieveFieldsExample.MainWindow"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <dx:PivotOlapDataSource x:Key="PivotOlapDataSource" Cube="Adventure Works" 
                                Catalog="Adventure Works DW Standard Edition" ConnectionTimeout="60" 
                                LocaleIdentifier="1033" Password="{x:Null}" Provider="MSOLAP" 
                                QueryTimeout="30" Server="http://demos.devexpress.com/Services/OLAP/msmdpump.dll" 
                                UserId="{x:Null}">
        </dx:PivotOlapDataSource>
    </Window.Resources>
    <Grid>
        <dxpg:PivotGridControl Name="pivotGridControl1" RowTreeMinWidth="170"
                               OlapDataProvider="Adomd" 
                               OlapConnectionString="{Binding ConnectionString, Source={StaticResource PivotOlapDataSource}}" />
    </Grid>
</Window>
using System.Windows;
using DevExpress.Xpf.PivotGrid;

namespace WpfOlapRetrieveFieldsExample {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();

            // Retrieves fields.
            pivotGridControl1.RetrieveFields(FieldArea.ColumnArea, false);

            // Adds some fields from the Field List to the specified area to create a report.
            pivotGridControl1.Fields["[Customer].[Country].[Country]"].Area = FieldArea.RowArea;
            pivotGridControl1.Fields["[Customer].[Country].[Country]"].Visible = true;
            pivotGridControl1.Fields["[Customer].[City].[City]"].Area = FieldArea.RowArea;
            pivotGridControl1.Fields["[Customer].[City].[City]"].Visible = true;
            pivotGridControl1.Fields["[Date].[Fiscal].[Fiscal Year]"].Area = FieldArea.ColumnArea;
            pivotGridControl1.Fields["[Date].[Fiscal].[Fiscal Year]"].Visible = true;
            pivotGridControl1.Fields["[Measures].[Internet Sales Amount]"].Visible = true;

            // Sets the Customization Forms style to Excel2007 with additional capabilities.
            pivotGridControl1.FieldListStyle = FieldListStyle.Excel2007;

            // Invokes the Field List.
            pivotGridControl1.ShowFieldList();
        }
    }
}
See Also