Back to Devexpress

PivotGridControl.CreateDrillDownDataSourceAsync() Method

wpf-devexpress-dot-xpf-dot-pivotgrid-dot-pivotgridcontrol-8bd9a083.md

latest9.5 KB
Original Source

PivotGridControl.CreateDrillDownDataSourceAsync() Method

Returns a list of records used to calculate a summary value for the specified cell asynchronously.

Namespace : DevExpress.Xpf.PivotGrid

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

NuGet Package : DevExpress.Wpf.PivotGrid

Declaration

csharp
public Task<PivotDrillDownDataSource> CreateDrillDownDataSourceAsync()
vb
Public Function CreateDrillDownDataSourceAsync As Task(Of PivotDrillDownDataSource)

Returns

TypeDescription
Task<PivotDrillDownDataSource>

An asynchronous operation that returns PivotDrillDownDataSource.

|

Remarks

Cells in the Pivot Grid display summary and total summary values. Each summary and total summary value is calculated for a specific subset of records in the control’s underlying data source. These records are identified by the values of the column and row fields displayed within the column and row headers.

The CreateDrillDownDataSourceAsync method allows you to retrieve the subset of records from the control’s underlying data source, used to calculate the summary value for the current cell.

In Server and OLAP modes, the CreateDrillDownDataSourceAsync method returns only visible fields. To get hidden field values, use the method’s overloads with the customColumns parameter that allows you to specify the columns to return.

Example

This example demonstrates how to obtain records from the control’s underlying data source for a selected cell or multiple selected cells asynchronously.

View Example: Pivot Grid for WPF - How to Display Underlying Records Asynchronously

The PivotGridControl.CellClick event raises when you click the Pivot Grid cell. The PivotGridControl.CreateDrillDownDataSourceAsync method returns the PivotDrillDownDataSource instance that contains underlying data for the current cell. The PivotDrillDownDataSource object is used as the Grid Control’s data source (it is assigned to the GridControl.ItemsSource property).

The PivotGridControl.CellSelectionChanged event raises when you select several Pivot Grid cells. The coordinates of the selected cells are obtained with the PivotGridControl.MultiSelection.SelectedCells notation. For each (X, Y) pair of cell coordinates, the PivotGridControl.CreateDrillDownDataSourceAsync method yields the PivotDrillDownDataSource object. The PivotDrillDownDataSource exposes an enumerator and supports an iteration over a collection of PivotDrillDownDataRow objects. The PivotDrillDownDataRow.ListSourceRowIndex property value is an index of the record in the original data source, so the source record is also available and can be added to a collection. The resulting collection is bound to GridControl for display.

cs
using DevExpress.Xpf.Core;
using DevExpress.Xpf.PivotGrid;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace WpfDrillDownDataSourceExample {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>

    public partial class MainWindow : ThemedWindow {
        public ObservableCollection<MyOrderRow> OrderSourceList { get; set; }
        public ObservableCollection<MyOrderRow> OrderDrillDownList { get; set; }
        public MainWindow() {
            InitializeComponent();
            OrderSourceList = DatabaseHelper.CreateData();
            pivotGridControl1.DataSource = OrderSourceList;
        }
        private async void PivotGridControl1_CellSelectionChanged(object sender, RoutedEventArgs e) {
            OrderDrillDownList = new ObservableCollection<MyOrderRow>();
            var selectionCopy = 
                pivotGridControl1.MultiSelection.SelectedCells.Cast().ToList();
            foreach (var cellPoint in selectionCopy) {
                foreach (PivotDrillDownDataRow record in 
                         await pivotGridControl1.CreateDrillDownDataSourceAsync(cellPoint.X, cellPoint.Y)) {

                    OrderDrillDownList.Add(OrderSourceList[record.ListSourceRowIndex]);
                }
            }
            gridControl1.ItemsSource = OrderDrillDownList;
        }
        private void ThemedWindow_Loaded(object sender, RoutedEventArgs e) {
            pivotGridControl1.BestFitArea = DevExpress.Xpf.PivotGrid.FieldBestFitArea.FieldHeader;
            pivotGridControl1.BestFit();
        }

        private async void pivotGridControl1_CellClick(object sender, PivotCellEventArgs e) {
            gridControl1.ItemsSource = 
                await pivotGridControl1.CreateDrillDownDataSourceAsync(e.ColumnIndex, e.RowIndex);
        }
    }
}
vb
Imports DevExpress.Xpf.Core
Imports DevExpress.Xpf.PivotGrid
Imports System.Collections.ObjectModel
Imports System.Linq
Imports System.Windows

Namespace WpfDrillDownDataSourceExample

    ''' <summary>
    ''' Interaction logic for MainWindow.xaml
    ''' </summary>
    ''' 
    Public Partial Class MainWindow
        Inherits ThemedWindow

        Public Property OrderSourceList As ObservableCollection(Of MyOrderRow)

        Public Property OrderDrillDownList As ObservableCollection(Of MyOrderRow)

        Public Sub New()
            Me.InitializeComponent()
            OrderSourceList = CreateData()
            Me.pivotGridControl1.DataSource = OrderSourceList
        End Sub

        Private Async Sub PivotGridControl1_CellSelectionChanged(ByVal sender As Object, ByVal e As RoutedEventArgs)
            OrderDrillDownList = New ObservableCollection(Of MyOrderRow)()
            Dim selectionCopy = pivotGridControl1.MultiSelection.SelectedCells.Cast(Of System.Drawing.Point)().ToList()
            For Each cellPoint In selectionCopy
                For Each record As PivotDrillDownDataRow In Await pivotGridControl1.CreateDrillDownDataSourceAsync(cellPoint.X, cellPoint.Y)

                    OrderDrillDownList.Add(OrderSourceList(record.ListSourceRowIndex))
                Next record
            Next cellPoint
            gridControl1.ItemsSource = OrderDrillDownList
        End Sub

        Private Sub ThemedWindow_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Me.pivotGridControl1.BestFitArea = FieldBestFitArea.FieldHeader
            Me.pivotGridControl1.BestFit()
        End Sub
        Private Async Sub pivotGridControl1_CellClick(ByVal sender As Object, ByVal e As PivotCellEventArgs)
            gridControl1.ItemsSource = Await pivotGridControl1.CreateDrillDownDataSourceAsync(e.ColumnIndex, e.RowIndex)
        End Sub

    End Class
xaml
<dx:ThemedWindow
    x:Class="WpfDrillDownDataSourceExample.MainWindow"
    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:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
    xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Width="800"
    Height="600"
    mc:Ignorable="d"
    Loaded="ThemedWindow_Loaded"
    Title="Create Drill-Down Data Source Example">

    <Grid>
    <!-- ... -->
        <dxpg:PivotGridControl
            x:Name="pivotGridControl1"
            Grid.Row="0"
            Grid.ColumnSpan="2"
            UseAsyncMode="true"
            CellClick="pivotGridControl1_CellClick"
            CellSelectionChanged="PivotGridControl1_CellSelectionChanged"
            DataProcessingEngine="Optimized">
            <!-- ... -->
        </dxpg:PivotGridControl>
        <!-- ... -->
    </Grid>

</dx:ThemedWindow>

See Also

PivotGridControl Class

PivotGridControl Members

DevExpress.Xpf.PivotGrid Namespace