Back to Devexpress

PivotGridControl.SetFieldSortingAsync(PivotGridField, PivotSortOrder) Method

windowsforms-devexpress-dot-xtrapivotgrid-dot-pivotgridcontrol-dot-setfieldsortingasync-x28-devexpress-dot-xtrapivotgrid-dot-pivotgridfield-devexpress-dot-xtrapivotgrid-dot-pivotsortorder-x29.md

latest6.1 KB
Original Source

PivotGridControl.SetFieldSortingAsync(PivotGridField, PivotSortOrder) Method

Sets the sort order for the specified field asynchronously.

Namespace : DevExpress.XtraPivotGrid

Assembly : DevExpress.XtraPivotGrid.v25.2.dll

NuGet Package : DevExpress.Win.PivotGrid

Declaration

csharp
public Task<bool> SetFieldSortingAsync(
    PivotGridField field,
    PivotSortOrder sortOrder
)
vb
Public Function SetFieldSortingAsync(
    field As PivotGridField,
    sortOrder As PivotSortOrder
) As Task(Of Boolean)

Parameters

NameTypeDescription
fieldPivotGridField

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

| | sortOrder | PivotSortOrder |

A PivotSortOrder enumeration member that specifies the field sort order.

|

Returns

TypeDescription
Task<Boolean>

An asynchronous operation that returns true in case of success.

|

Remarks

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

The PivotGridFieldBase.SortOrder property specifies the field sort order.

To toggle the field sort order, use the following methods:

PivotGridControl.ChangeFieldSortOrderAsyncToggles the sort order of the specified field asynchronously.PivotGridFieldBase.ChangeSortOrderToggles the sort order for the current field.

Example

The example below sets the Country‘s sort order to descending.

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";
            //...
            await pivotGridControl1.EndUpdateAsync();

            await pivotGridControl1.SetFieldSortingAsync(fieldCountry,PivotSortOrder.Descending);
        }
    }
}
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"
            '...
            Await pivotGridControl1.EndUpdateAsync()

            Await pivotGridControl1.SetFieldSortingAsync(fieldCountry,PivotSortOrder.Descending)
        End Sub
    End Class
End Namespace

See Also

SortOrder

ChangeSortOrder()

ChangeFieldSortOrderAsync

PivotGridControl Class

PivotGridControl Members

DevExpress.XtraPivotGrid Namespace