Skip to main content

PivotGridControl.RetrieveFieldsAsync(PivotArea, Boolean) Method

Creates PivotGridField objects for all columns in a data source and specifies the area and visibility of the fields. This method executes these actions asynchronously.

Namespace: DevExpress.XtraPivotGrid

Assembly: DevExpress.XtraPivotGrid.v24.2.dll

Declaration

public Task<bool> RetrieveFieldsAsync(
    PivotArea area,
    bool visible
)

Parameters

Name Type Description
area PivotArea

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

visible Boolean

true to show the created fields; otherwise, false.

Returns

Type Description
Task<Boolean>

An asynchronous operation that returns true in case of success.

Remarks

This overload clears the PivotGridControl.Fields collection and populates it with new PivotGridField objects, created for all columns in a data source.

The RetrieveFieldsAsync 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 DataSourceColumnBindingBase.ColumnName property is set to the name of the data source column. The created fields are moved to the area specified by the area parameter. The visible parameter specifies whether these fields are created as visible or hidden.

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

The RetrieveFieldsAsync method is asynchronous. RetrieveFieldsAsync starts to execute the related operation in a background thread, and returns the Pivot Grid control. The main UI thread remains unblocked to allow the application to continue responding to user actions. Refer to the following topic for more information: Asynchronous Mode.

Use the PivotGridControl.RetrieveFields method to retrieve fields synchronously.

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

Example

The following code snippet shows how to create and configure Pivot Grid fields asynchronously in OLAP mode:

using DevExpress.XtraPivotGrid;
using System.Windows.Forms;

namespace WindowsFormsApp2 {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
            pivotGridControl1.OLAPConnectionString = "Provider=msolap;" +
                "Data Source=http://demos.devexpress.com/Services/OLAP/msmdpump.dll;" +
                "Initial Catalog=Adventure Works DW Standard Edition;" +
                "Cube Name=Adventure Works;";
            pivotGridControl1.OptionsBehavior.UseAsyncMode = true;
            ConfigureLayout();
        }
        async void ConfigureLayout() {
            await pivotGridControl1.RetrieveFieldsAsync(PivotArea.FilterArea, false);
            foreach (PivotGridField field in pivotGridControl1.Fields) {
                field.Name = "field" + (field.DataBinding as DataSourceColumnBinding).ColumnName;
            }
            pivotGridControl1.BeginUpdate();

            pivotGridControl1.Fields["[Customer].[Country].[Country]"].Area = PivotArea.RowArea;
            pivotGridControl1.Fields["[Customer].[Country].[Country]"].Caption = "Country";
            pivotGridControl1.Fields["[Customer].[Country].[Country]"].Visible = true;
            pivotGridControl1.Fields["[Date].[Fiscal].[Fiscal Year]"].Area = PivotArea.ColumnArea;
            pivotGridControl1.Fields["[Date].[Fiscal].[Fiscal Year]"].Visible = true;
            pivotGridControl1.Fields["[Date].[Fiscal].[Fiscal Year]"].Caption = "Date";
            pivotGridControl1.Fields["[Measures].[Internet Sales Amount]"].Area = PivotArea.DataArea;
            pivotGridControl1.Fields["[Measures].[Internet Sales Amount]"].Visible = true;
            pivotGridControl1.Fields["[Measures].[Internet Sales Amount]"].Caption = "Sales";

            await pivotGridControl1.EndUpdateAsync();

        }
    }
}
See Also