Back to Devexpress

PivotGridFieldBase.DataBinding Property

corelibraries-devexpress-dot-xtrapivotgrid-dot-pivotgridfieldbase-adc03374.md

latest11.2 KB
Original Source

PivotGridFieldBase.DataBinding Property

Gets or sets an object that specifies the Pivot Grid field’s source data.

Namespace : DevExpress.XtraPivotGrid

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

NuGet Packages : DevExpress.PivotGrid.Core, DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue(null)]
public DataBindingBase DataBinding { get; set; }
vb
<DefaultValue(Nothing)>
Public Property DataBinding As DataBindingBase

Property Value

TypeDefaultDescription
DataBindingBasenull

A DataBindingBase descendant that specifies the source data and calculation type.

|

Remarks

Pivot Grid uses the Binding API to bind Pivot Grid fields to data. A data binding source can be a column in the data source or a calculated expression.

The following types of bindings are available:

Column Binding Allows you to bind a Pivot Grid field to a data column in the data source. The Pivot Grid field obtains its values from a field in the data source.Expression BindingAllows you to bind a Pivot Grid field to an expression and display the calculated result. The expression can be a formula or an aggregate function.Calculation BindingAllows you to bind a Pivot Grid field to a window calculation and display aggregated values in the window.

Each specified binding object is a DataBindingBase descendant. This object is assigned to the Pivot Grid field’s DataBinding property.

Refer to the following topic for more information about binding concepts and usage examples: Data Binding API.

The following table illustrates Pivot Grid data processing modes that support the Binding API:

Legacy and Legacy OptimizedOptimizedServer modeOLAP
Column Binding
Expression Binding
Calculation Binding

Refer to the following article for more information about data processing modes: Pivot Grid Data Processing Modes.

Example

The following example shows how to use the expression binding to bind the FirstValue([ProductName]) expression to the First Product Sold field. The expression returns the first product sold by Sales Persons in each product category:

View Example

cs
using DevExpress.XtraPivotGrid;
using System.Windows.Forms;

namespace WinPivot_CustomFunctions {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();     
            // ...
            PivotGridField pivotGridField1 = new PivotGridField() {
                Area = PivotArea.DataArea,
                AreaIndex = 0,
                Caption = "First Product Sold",
                FieldName = "FirstProductSold"
            };
            pivotGridControl1.Fields.Add(pivotGridField1);
            pivotGridField1.DataBinding = new ExpressionDataBinding() { 
                Expression = "FirstValue([ProductName])" };
                // ...
        }      
    }
}
vb
Imports System.Windows.Forms
Imports DevExpress.XtraPivotGrid

Namespace WinPivot_CustomFunctions
    Partial Public Class Form1
        Inherits Form
        Public Sub New()
            InitializeComponent()
            ' ...
            pivotGridControl1.OptionsData.DataProcessingEngine = PivotDataProcessingEngine.Optimized
            Dim pivotGridField1 As New PivotGridField() With {
                .Area = PivotArea.DataArea,
                .AreaIndex = 0,
                .Caption = "First Product Sold",
                .FieldName = "FirstProductSold"
            }
            pivotGridControl1.Fields.Add(pivotGridField1)
            pivotGridField1.DataBinding = New ExpressionDataBinding() With {.Expression = "FirstValue([ProductName])"}
            ' ...
            pivotGridField1.Options.ShowGrandTotal = False
        End Sub
    End Class

The following code snippets (auto-collected from DevExpress Examples) contain references to the DataBinding 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.

winforms-pivot-grid-connect-to-an-olap-datasource/CS/WinOlapRetrieveFieldsExample/Form1.cs#L54

csharp
PivotGridField fieldCountry = pivotGridControl1.Fields.Add("Country", PivotArea.RowArea);
fieldCountry.DataBinding = new DataSourceColumnBinding("[Customer].[Country].[Country]");
fieldCountry.Name = "fieldCountry";

winforms-pivot-grid-custom-group-intervals/CS/CustomGroupIntervals/Form1.cs#L18

csharp
DataSourceColumnBinding country = new DataSourceColumnBinding("Country");
pivotGridFieldCountry.DataBinding = country;
pivotGridControl1.Fields.Add(pivotGridFieldCountry);

winforms-pivot-grid-hide-the-grand-total-column-and-text-labels/CS/RemoveGridLinesExample/Form1.cs#L33

csharp
fieldYear.Area = PivotArea.RowArea;
fieldYear.DataBinding = new DataSourceColumnBinding("Date", PivotGroupInterval.DateYear);
fieldYear.Name = "FieldYear";

web-forms-pivot-grid-calculate-running-totals/CS/RunningTotal/Default.aspx.cs#L15

csharp
RunningTotalBinding runningBinding = new RunningTotalBinding(dsBinding, criteria, PivotSummaryType.Sum);
    fieldProductAmount.DataBinding = runningBinding;
}

winforms-pivotgrid--display-the-difference-of-income-and-outlay-in-totals/CS/PivotGridCustomSummaryExample/Form1.cs#L86

csharp
ExpressionDataBinding savingsBinding = new ExpressionDataBinding("Sum(Iif([Type]='Income', [Value], -[Value]))");
    fieldValueTotal.DataBinding = savingsBinding;
}

winforms-pivot-change-summarydisplaytype-in-context-menu/VB/WindowsApplication34/Form1.vb#L61

vb
Case PivotSummaryDisplayType.AbsoluteVariation
    field.DataBinding = New DifferenceBinding(sourceBinding, CalculationPartitioningCriteria.RowValue, CalculationDirection.DownThenAcross, DifferenceTarget.Previous, DifferenceType.Absolute)
Case PivotSummaryDisplayType.PercentVariation

winforms-pivot-grid-connect-to-an-olap-datasource/VB/WinOlapRetrieveFieldsExample/Form1.vb#L52

vb
Dim fieldCountry As PivotGridField = pivotGridControl1.Fields.Add("Country", PivotArea.RowArea)
fieldCountry.DataBinding = New DataSourceColumnBinding("[Customer].[Country].[Country]")
fieldCountry.Name = "fieldCountry"

winforms-pivot-grid-custom-group-intervals/VB/CustomGroupIntervals/Form1.vb#L20

vb
Dim country As DataSourceColumnBinding = New DataSourceColumnBinding("Country")
pivotGridFieldCountry.DataBinding = country
pivotGridControl1.Fields.Add(pivotGridFieldCountry)

winforms-pivot-grid-hide-the-grand-total-column-and-text-labels/VB/RemoveGridLinesExample/Form1.vb#L39

vb
fieldYear.Area = PivotArea.RowArea
fieldYear.DataBinding = New DataSourceColumnBinding("Date", PivotGroupInterval.DateYear)
fieldYear.Name = "FieldYear"

web-forms-pivot-grid-calculate-running-totals/VB/RunningTotal/Default.aspx.vb#L16

vb
Dim runningBinding As RunningTotalBinding = New RunningTotalBinding(dsBinding, criteria, PivotSummaryType.Sum)
    fieldProductAmount.DataBinding = runningBinding
Else

See Also

Optimized Calculation Engine

Data Binding API

PivotGridFieldBase Class

PivotGridFieldBase Members

DevExpress.XtraPivotGrid Namespace