Edit this page

Drill Down

The value of a particular PivotCellElement is calculated depending on the applied row and column groups together with the aggregate descriptions.

The LocalDataSourceProvider exposes a GetUnderlyingData method which allows extracting the records from the data source object responsible for accumulating the result for a particular row and column. The GetUnderlyingData method is working with two parameters: Row Group and Column Group.

In the example below we will handle RadPivotGrid.MouseDoubleClick event and use the retrieved IEnumerable object to bind RadGridView and display the result.

Figure 1: RadPivotGrid Drill Down Data

pivotgrid-drilldown 001

GetUnderlyingData Method

private void radPivotGrid1_MouseDoubleClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        RadPivotGrid pivotGrid = (RadPivotGrid)sender;
        PivotCellElement cell = pivotGrid.ElementTree.GetElementAtPoint(e.Location) as PivotCellElement;
        if (cell != null)
        {
            var row = cell.Row.Group;
            var column = cell.Column.Group;
            LocalDataSourceProvider localProvider = pivotGrid.DataProvider as LocalDataSourceProvider;
            localProvider.GetUnderlyingData(row, column);
        }
    }
}

Private Sub radPivotGrid1_MouseDoubleClick(sender As Object, e As MouseEventArgs)
    If e.Button = MouseButtons.Left Then
        Dim pivotGrid As RadPivotGrid = DirectCast(sender, RadPivotGrid)
        Dim cell As PivotCellElement = TryCast(pivotGrid.ElementTree.GetElementAtPoint(e.Location), PivotCellElement)
        If cell IsNot Nothing Then
            Dim row = cell.Row.Group
            Dim column = cell.Column.Group
            Dim localProvider As LocalDataSourceProvider = TryCast(pivotGrid.DataProvider, LocalDataSourceProvider)
            localProvider.GetUnderlyingData(row, column)
        End If
    End If
End Sub

The underlying data can be retrieved by handling the GetUnderlyingDataCompleted event and accessing the DrillDownCompletedEventArgs arguments:

  • Result: An IEnumerable representing the result of the underlying data extraction operation.
  • InnerExceptions: A read-only collection with the thrown exceptions during the underlying data extraction.
note

If the DeferUpdates property of the LocalDataSourceProvider is set to true, calling the GetUnderlyingData method without first updating the provider will result in an InvalidOperationException.

important

The underlying data is extracted asynchronously when using the assemblies built for .NET 4.0. In this respect it is necessary to use BeginInvoke if the retrieved data will be used on the UI thread.

GetUnderlyingDataCompleted Event

private void provider_GetUnderlyingDataCompleted(object sender, Telerik.Pivot.Core.DrillDown.DrillDownCompletedEventArgs e)
{
    IEnumerable underlyingData = e.Result;
    this.radGridView1.BeginInvoke(new Action(() =>
    {
        if (e.InnerExceptions.Count == 0)
        {
            this.radGridView1.DataSource = underlyingData;
        }
    }));
}

Private Sub provider_GetUnderlyingDataCompleted(sender As Object, e As Telerik.Pivot.Core.DrillDown.DrillDownCompletedEventArgs)
    Dim underlyingData As IEnumerable = e.Result
    Me.radGridView1.BeginInvoke(New Action(Function()
                                               If e.InnerExceptions.Count = 0 Then
                                                   Me.radGridView1.DataSource = underlyingData
                                               End If
                                           End Function))
End Sub

See Also