Back to Devexpress

PivotGridControl.RetrieveFieldsAsync(PivotArea, Boolean) Method

windowsforms-devexpress-dot-xtrapivotgrid-dot-pivotgridcontrol-dot-retrievefieldsasync-x28-devexpress-dot-xtrapivotgrid-dot-pivotarea-system-dot-boolean-x29.md

latest8.5 KB
Original Source

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.v25.2.dll

NuGet Package : DevExpress.Win.PivotGrid

Declaration

csharp
public Task<bool> RetrieveFieldsAsync(
    PivotArea area,
    bool visible
)
vb
Public Function RetrieveFieldsAsync(
    area As PivotArea,
    visible As Boolean
) As Task(Of Boolean)

Parameters

NameTypeDescription
areaPivotArea

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

TypeDescription
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:

csharp
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();

        }
    }
}
vb
Imports DevExpress.XtraPivotGrid
Imports System.Windows.Forms

Namespace WindowsFormsApp2
    Partial Public Class Form1
        Inherits Form

        Public Sub New()
            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()
        End Sub
        Private Async Sub ConfigureLayout()
            Await pivotGridControl1.RetrieveFieldsAsync(PivotArea.FilterArea, False)
            For Each field As PivotGridField In pivotGridControl1.Fields
                field.Name = "field" & (TryCast(field.DataBinding, DataSourceColumnBinding)).ColumnName
            Next field
            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()

        End Sub
    End Class
End Namespace

See Also

RetrieveFields

Fields

FieldName

Asynchronous Mode

Pivot Grid Fields

PivotGridControl Class

PivotGridControl Members

DevExpress.XtraPivotGrid Namespace