Back to Devexpress

PivotGridControl.DataSource Property

wpf-devexpress-dot-xpf-dot-pivotgrid-dot-pivotgridcontrol-6830314e.md

latest14.4 KB
Original Source

PivotGridControl.DataSource Property

Gets or sets the PivotGridControl data source.

Namespace : DevExpress.Xpf.PivotGrid

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

NuGet Package : DevExpress.Wpf.PivotGrid

Declaration

csharp
[Bindable(true)]
public object DataSource { get; set; }
vb
<Bindable(True)>
Public Property DataSource As Object

Property Value

TypeDescription
Object

An object that contains data for PivotGridControl.

|

Remarks

Assigning a new value to the DataSource property raises the PivotGridControl.DataSourceChanged event, and causes a pivot grid update.

PivotGridControl is not updated automatically when the current data source is modified. To force the pivot grid update, use the PivotGridControl.ReloadData method.

To recalculate summary values without reloading data from the underlying data source, use the PivotGridControl.RefreshData method.

Note

The PivotGridControl.DataSourceChanged event is raised and the pivot grid is updated when the data source implementing the IBindingList interface raises the ListChanged event of the PropertyDescriptorAdded, PropertyDescriptorDeleted, PropertyDescriptorChanged or Reset type.

To retrieve data from a data source asynchronously, assign it using the PivotGridControl.SetDataSourceAsync method instead of the DataSource property.

Example

The following example demonstrates how to bind the PivotGridControl to a “SalesPerson” view in the nwind.mdb database, which is shipped with the installation. The control will be used to analyse sales per country, customers, product categories and years.

The following steps were used to created this example:

  1. A typed dataset is created from the database at design time.
  2. Instances of SalesPersonDataTable and SalesPersonTableAdapter objects are created.
  3. The PivotGridControl is bound to the SalesPersonDataTable instance via the PivotGridControl.DataSource property.
  4. The table is filled with data in the Window_Loaded event handler.

The pivot grid fields that will represent data source fields are created in XAML markup. They are positioned within appropriate areas to analyze the data in the way you want.

Note that if you want to see an example of how to programmatically add pivot grid fields, please refer to the How to: Bind a PivotGrid to an MS Access Database Programmatically example.

xaml
<Window x:Class="HowToBindToMDB.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
    <Grid>
        <dxpg:PivotGridControl Name="pivotGridControl1" DataProcessingEngine="Optimized">
            <dxpg:PivotGridControl.Fields>
                <dxpg:PivotGridField Name="fieldCountry" Area="RowArea">
                    <dxpg:PivotGridField.DataBinding>
                        <dxpg:DataSourceColumnBinding ColumnName="Country"/>
                    </dxpg:PivotGridField.DataBinding>
                </dxpg:PivotGridField>
                <dxpg:PivotGridField Name="fieldCustomer" Area="RowArea"
                                     Caption="Customer">
                    <dxpg:PivotGridField.DataBinding>
                        <dxpg:DataSourceColumnBinding ColumnName="Sales Person"/>
                    </dxpg:PivotGridField.DataBinding>
                </dxpg:PivotGridField>
                <dxpg:PivotGridField Name="fieldYear" Area="ColumnArea" Caption="Year" >
                    <dxpg:PivotGridField.DataBinding>
                        <dxpg:DataSourceColumnBinding ColumnName="OrderDate" GroupInterval="DateYear"/>
                    </dxpg:PivotGridField.DataBinding>
                </dxpg:PivotGridField>
                <dxpg:PivotGridField Name="fieldCategoryName" Area="ColumnArea" Caption="Product Category">
                    <dxpg:PivotGridField.DataBinding>
                        <dxpg:DataSourceColumnBinding ColumnName="CategoryName"/>
                    </dxpg:PivotGridField.DataBinding>
                </dxpg:PivotGridField>
                <dxpg:PivotGridField Name="fieldProductName" Area="FilterArea" Caption="Product Name">
                    <dxpg:PivotGridField.DataBinding>
                        <dxpg:DataSourceColumnBinding ColumnName="ProductName"/>
                    </dxpg:PivotGridField.DataBinding>
                </dxpg:PivotGridField>
                <dxpg:PivotGridField Name="fieldExtendedPrice" Area="DataArea" CellFormat="c0">
                    <dxpg:PivotGridField.DataBinding>
                        <dxpg:DataSourceColumnBinding ColumnName="Extended Price"/>
                    </dxpg:PivotGridField.DataBinding>
                </dxpg:PivotGridField>
            </dxpg:PivotGridControl.Fields>
        </dxpg:PivotGridControl>
    </Grid>
</Window>
cs
using System.Data;
using System.Data.OleDb;
using System.Windows;
using DevExpress.Xpf.PivotGrid;
using HowToBindToMDB.NwindDataSetTableAdapters;

namespace HowToBindToMDB {
    public partial class MainWindow : Window {
        NwindDataSet.SalesPersonDataTable salesPersonDataTable = 
            new NwindDataSet.SalesPersonDataTable();
        SalesPersonTableAdapter salesPersonDataAdapter = new SalesPersonTableAdapter();

        public MainWindow() {
            InitializeComponent();
            pivotGridControl1.DataSource = salesPersonDataTable;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e) {
            salesPersonDataAdapter.Fill(salesPersonDataTable);
        }
    }
}
vb
Imports System.Windows
Imports HowToBindToMDB.NwindDataSetTableAdapters

Namespace HowToBindToMDB

    Public Partial Class MainWindow
        Inherits Window

        Private salesPersonDataTable As NwindDataSet.SalesPersonDataTable = New NwindDataSet.SalesPersonDataTable()

        Private salesPersonDataAdapter As SalesPersonTableAdapter = New SalesPersonTableAdapter()

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

        Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            salesPersonDataAdapter.Fill(salesPersonDataTable)
        End Sub
    End Class
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references to the DataSource property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-pivotgrid-customize-filter-drop-down/CS/WpfPivotCustomFilterDropDownExample/MainWindow.xaml#L42

xml
<Grid>
    <dxpg:PivotGridControl DataSource="{Binding Path=Data, Source={StaticResource ExcelItemsSource}}"
                           Name="pivotGridControl1"

wpf-pivot-grid-apply-format-conditions-to-data-cells/CS/WpfPivotGridConditionalFormatting/MainWindow.xaml#L22

xml
<dxpg:PivotGridControl Name="pivotGridControl1"
                       DataSource="{Binding Path=Data, Source={StaticResource TypedSimpleSource}}"
                       AllowConditionalFormattingMenu="True"

wpf-pivot-grid-obtain-underlying-data/CS/ObtainUnderlyingData/MainWindow.xaml#L42

xml
<Grid>
    <dxpg:PivotGridControl x:Name="pivot" DataSource="{Binding DataSource}" RowTreeWidth="170"
                           DataProcessingEngine="Optimized">

wpf-pivot-grid-add-custom-field-values-rows-columns-not-present-in-datasource/CS/WpfApplication1/MainWindow.xaml.cs#L36

csharp
Table = CreatePivotTable(100);
    pivot.DataSource = Table;
}

wpf-pivot-grid-split-field-value-cells/CS/Window1.xaml.cs#L17

csharp
PivotHelper.FillPivot(pivotGrid);
pivotGrid.DataSource = PivotHelper.GetDataTable();
pivotGrid.BestFit();

wpf-pivot-grid-bind-to-an-mdb-database/CS/HowToBindToMDB/MainWindow.xaml.cs#L27

csharp
// Assign the data source to the PivotGrid control.
pivotGridControl1.DataSource = sourceDataSet.Tables["SalesPerson"];

wpf-pivotgrid-how-to-display-underlying-data-asynchronously/CS/WpfDrillDownDataSourceExample/MainWindow.xaml.cs#L19

csharp
OrderSourceList = DatabaseHelper.CreateData();
    pivotGridControl1.DataSource = OrderSourceList;
}

wpf-pivot-grid-hide-specific-columns-and-row/CS/WpfApp/MainWindow.xaml.cs#L21

csharp
PivotGridControl pivot = (PivotGridControl)sender;
if (pivot.DataSource == null) return;
if (radioListBoxEdit.SelectedIndex == 0) return;

wpf-pivot-grid-bind-to-an-mdb-database/VB/HowToBindToMDB/MainWindow.xaml.vb#L26

vb
' Assign the data source to the PivotGrid control.
pivotGridControl1.DataSource = sourceDataSet.Tables("SalesPerson")

wpf-pivot-grid-hide-specific-columns-and-row/VB/WpfApp/MainWindow.xaml.vb#L25

vb
Dim pivot As PivotGridControl = CType(sender, PivotGridControl)
If pivot.DataSource Is Nothing Then
    Return

wpf-pivotgrid-customize-the-cell-template/VB/HowToCustomizeCellTemplate/MainWindow.xaml.vb#L19

vb
OrderSourceList = DatabaseHelper.CreateData()
pivotGridControl1.DataSource = OrderSourceList
pivotGridControl1.BestFitArea = DevExpress.Xpf.PivotGrid.FieldBestFitArea.FieldHeader

wpf-pivot-grid-change-summary-display-type/VB/HeaderMenuCustomizationExample/MainWindow.xaml.vb#L17

vb
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
    pivotGridControl1.DataSource = CreatePivotDataSource()
End Sub

wpf-pivot-grid-define-custom-cell-template-to-performing-data-editing/VB/HowToEditCell/MainWindow.xaml.vb#L22

vb
OrderSourceList = DatabaseHelper.CreateData()
pivotGridControl1.DataSource = OrderSourceList
pivotGridControl1.BestFit()

See Also

PivotGridControl Class

PivotGridControl Members

DevExpress.Xpf.PivotGrid Namespace