Back to Devexpress

PivotGridControl.RetrieveFields() Method

wpf-devexpress-dot-xpf-dot-pivotgrid-dot-pivotgridcontrol-3e4d0c20.md

latest9.3 KB
Original Source

PivotGridControl.RetrieveFields() Method

Creates PivotGridField objects for all columns in the bound data source.

Namespace : DevExpress.Xpf.PivotGrid

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

NuGet Package : DevExpress.Wpf.PivotGrid

Declaration

csharp
public void RetrieveFields()
vb
Public Sub RetrieveFields

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.

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

xaml
<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>
cs
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();
        }
    }
}
vb
Imports System.Windows
Imports DevExpress.Xpf.PivotGrid

Namespace WpfOlapRetrieveFieldsExample
    ''' <summary>
    ''' Interaction logic for MainWindow.xaml
    ''' </summary>
    Partial Public Class MainWindow
        Inherits Window

        Public Sub New()
            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()
        End Sub
    End Class
End Namespace

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the RetrieveFields() method.

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-pivot-grid-show-top-n-values-in-context-menu/CS/ContextMenuToShowTopN_Example/MainWindow.xaml.cs#L38

csharp
pivotGridControl1.DataSource = xlDataSource;
pivotGridControl1.RetrieveFields();
pivotGridControl1.Fields["Sales Person"].Area = FieldArea.RowArea;

wpf-pivot-grid-show-top-n-values-in-context-menu/VB/ContextMenuToShowTopN_Example/MainWindow.xaml.vb#L35

vb
pivotGridControl1.DataSource = xlDataSource
pivotGridControl1.RetrieveFields()
pivotGridControl1.Fields("Sales Person").Area = FieldArea.RowArea

See Also

RetrieveFieldsAsync

Fields

Name

Fields

Filter Header Area

PivotGridControl Class

PivotGridControl Members

DevExpress.Xpf.PivotGrid Namespace