Back to Devexpress

Bind Pivot Grid Fields to Data Columns

wpf-404335-controls-and-libraries-pivot-grid-binding-to-data-olap-data-source-bind-pivot-grid-fields-to-data-columns.md

latest2.6 KB
Original Source

Bind Pivot Grid Fields to Data Columns

  • Aug 10, 2023
  • 2 minutes to read

This topic describes how to use the Binding API to bind a Pivot Grid field to a measure or dimension in OLAP mode.

Important

You cannot bind the Pivot Grid to data at design time in .NET 5+ projects.

Follow the steps below to bind a Pivot Grid’s field to a measure or dimension in code:

  1. Create a DataSourceColumnBinding instance.

  2. Specify the DataSourceColumnBinding.ColumnName property. ColumnName must specify the full name of the bound measure or dimension.

  3. Assign the DataSourceColumnBinding object to the PivotGridField.DataBinding property.

View Example: Pivot Grid for WPF - Bind a PivotGrid to an OLAP Cube

The following code snippet illustrates how to create the fieldMeasuresInternetSalesAmount field and bind it to the Internet Sales Amount measure:

csharp
using System.Windows;
using DevExpress.Xpf.PivotGrid;

namespace HowToBindOLAP {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent(); 
         }
         private void Window_Loaded(object sender, RoutedEventArgs e) {
           // ...
           PivotGridField fieldMeasuresInternetSalesAmount = 
                new PivotGridField("[Measures].[Internet Sales Amount]", FieldArea.DataArea);
            fieldMeasuresInternetSalesAmount.Caption = "Internet Sales Amount";
            pivotGridControl1.Fields.Add(fieldMeasuresInternetSalesAmount); 
         }
    }
}
vb
Imports System.Windows
Imports DevExpress.Xpf.PivotGrid

Namespace HowToBindOLAP
    Partial Public Class MainWindow
        Inherits Window

        Public Sub New()
            InitializeComponent()
        End Sub
         Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
           ' ...
           Dim fieldMeasuresInternetSalesAmount As New PivotGridField("[Measures].[Internet Sales Amount]", FieldArea.DataArea)
            fieldMeasuresInternetSalesAmount.Caption = "Internet Sales Amount"
            pivotGridControl1.Fields.Add(fieldMeasuresInternetSalesAmount)
         End Sub
    End Class
End Namespace