Back to Devexpress

PivotGridControl.ChangeFieldSortOrderAsync(PivotGridField) Method

windowsforms-devexpress-dot-xtrapivotgrid-dot-pivotgridcontrol-dot-changefieldsortorderasync-x28-devexpress-dot-xtrapivotgrid-dot-pivotgridfield-x29.md

latest6.0 KB
Original Source

PivotGridControl.ChangeFieldSortOrderAsync(PivotGridField) Method

Toggles the sort order of the specified field asynchronously.

Namespace : DevExpress.XtraPivotGrid

Assembly : DevExpress.XtraPivotGrid.v25.2.dll

NuGet Package : DevExpress.Win.PivotGrid

Declaration

csharp
public Task<bool> ChangeFieldSortOrderAsync(
    PivotGridField field
)
vb
Public Function ChangeFieldSortOrderAsync(
    field As PivotGridField
) As Task(Of Boolean)

Parameters

NameTypeDescription
fieldPivotGridField

A PivotGridField object that specifies a field whose sort order should be toggled.

|

Returns

TypeDescription
Task<Boolean>

An asynchronous operation that returns true in case of success.

|

Remarks

The ChangeFieldSortOrderAsync method is asynchronous. ChangeFieldSortOrderAsync 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.

You can also use the PivotGridControl.SetFieldSortingAsync method to specify the sort order for a field asynchronously.

The PivotGridFieldBase.SortOrder property specifies the field sort order. To toggle the field sort order synchronously, use the PivotGridFieldBase.ChangeSortOrder method.

Example

The example below inverts the sort order of the Country field values. The field’s SortOrder property is set to Descending but the ChangeFieldSortOrderAsync method changes the specified sort order and the Pivot Grid displays the Country field values in ascending order.

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() {
            pivotGridControl1.BeginUpdate();
            // Create and configure Pivot Grid fields
            PivotGridField fieldCountry = pivotGridControl1.Fields.Add("Country", PivotArea.ColumnArea);
            fieldCountry.DataBinding = new DataSourceColumnBinding("[Customer].[Country].[Country]");
            fieldCountry.Name = "fieldCountry";
            fieldCountry.SortOrder = PivotSortOrder.Descending;
            //...
            await pivotGridControl1.EndUpdateAsync();

            await pivotGridControl1.ChangeFieldSortOrderAsync(fieldCountry);
        }
    }
}
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()
            pivotGridControl1.BeginUpdate()
            ' Create and configure Pivot Grid fields
            Dim fieldCountry As PivotGridField = pivotGridControl1.Fields.Add("Country", PivotArea.ColumnArea)
            fieldCountry.DataBinding = New DataSourceColumnBinding("[Customer].[Country].[Country]")
            fieldCountry.Name = "fieldCountry"
            fieldCountry.SortOrder = PivotSortOrder.Descending
            '...
            Await pivotGridControl1.EndUpdateAsync()

            Await pivotGridControl1.ChangeFieldSortOrderAsync(fieldCountry)
        End Sub
    End Class
End Namespace

See Also

SetFieldSortingAsync

SortOrder

ChangeSortOrder()

PivotGridControl Class

PivotGridControl Members

DevExpress.XtraPivotGrid Namespace