[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Collapse]Pivot Grid
   [Expand]Getting Started
   [Expand]Fundamentals
   [Collapse]Binding to Data
     Binding to Data Overview
    [Expand]Data Source Configuration Wizard
    [Expand]OLAP Data Source
    [Expand]Database Server Mode
     Unbound Fields
     Local Data Stores
     Asynchronous Mode
   [Expand]Data Shaping
   [Expand]Data Analysis
   [Expand]Layout
   [Expand]Focus and Navigation
   [Expand]Printing and Exporting
   [Expand]Appearance
   [Expand]Design-time Features
   [Expand]Miscellaneous
   [Expand]UI Elements
   [Expand]End-User Capabilities
   [Expand]Examples
   [Expand]Member Tables
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Unbound Fields

The Pivot Grid supports bound and unbound fields:

  • Bound fields retrieve data from the pivot grid's underlying data source.
  • Unbound fields get data by evaluating an expression or handling an event. You can use unbound fields to construct and display user-friendly values in field headers:

You can sort, group and filter unbound fields in the same manner as bound fields.

Note

Unbound fields cannot be used in OLAP mode.

Tip

If you have the Demo Center installed, review the Unbound Fields demo.

This topic consists of the following sections:

Expanded Create an Unbound Field in Visual Studio Designer

Follow the steps below to create a new unbound field in the PivotGrid control.

  1. Click 'Run Designer' on the PivotGrid's smart tag panel. In the PivotGrid Designer window, select the Fields page and click or to add a new field. You can also use the Field collection editor from the PivotGridControl Properties window.

  2. The PivotGridFieldBase.UnboundFieldName property is assigned automatically. You can change this value, but make sure that its value is not equal to existing PivotGridFieldBase.Name or PivotGridFieldBase.FieldName values.
  3. Change the value of the field's PivotGridFieldBase.UnboundType property from Bound to a value type from the drop-down list.

  4. Specify an expression to fill the field with data. Click the PivotGridField.UnboundExpression property's ellipsis button and enter the expression in the invoked Expression Editor:

    Refer to the Pivot Grid Expression Syntax document for more information about the expression operators and functions.

    Tip

    You can handle the CustomUnboundFieldData event to supply data to unbound fields.

Expanded Create an Unbound Field in Code

To create an unbound field in code, create the PivotGridField instance, specify the field name, type, and other settings, and add the resulting object to the PivotGridControl.Fields collection.

The following code snippet demonstrates how to create an unbound field in code and use the PivotGridField.UnboundExpression property to supply data. In this example, extended price values are calculated as follows:

[Quantity] * [UnitPrice] * (1 - [Discount]).

Pivot Grid field names are obtained using the PivotGridFieldBase.ExpressionFieldName property.

Expanded Provide Data Using the Event

You can handle the PivotGridControl.CustomUnboundFieldData event for complex calculations that cannot be performed using expressions. The PivotGrid control fires this event for each unbound field and row in the data source.

Note

The server and OLAP modes do not support the PivotGridControl.CustomUnboundFieldData event.

The code snippet below demonstrates how to create an unbound field in code and supply it with data using the PivotGridControl.CustomUnboundFieldData event. In this example, extended price values are calculated manually using the formula UnitPrice * Quantity * (1-Discount).

Expanded Change Unbound Expression Mode

The PivotGridFieldBase.UnboundExpressionMode property allows you to change the unbound field expression's calculation mode. The following table lists the available modes:

Unbound Expression Mode Description
UnboundExpressionMode.DataSource The UnboundExpressionMode.DataSource mode allows you to compute unbound field values on a data source level. In the image below, the ExtendedPrice field is calculated based on the underlying UnitPrice and Quantity values.

After you add the created unbound field to the Data Header area, the Pivot Grid uses the specified summary function to summarize its data.

In this case, unbound field values are calculated before summarization.

UnboundExpressionMode.UseSummaryValues The UnboundExpressionMode.UseSummaryValues mode enables you to compute unbound field values on a visualization (or summary) level. In this case, the Pivot Grid uses the displayed data to compute unbound field values.

To calculate a margin for a product, you have to divide its Profit value by its ExtendedPrice value.

In this mode, an expression uses summaries.

Note

Hidden data source fields or fields in the Filter Header area are not summarized and cannot participate in the calculation. To avoid this restriction, use the UnboundExpressionMode.UseAggregateFunctions mode. This mode , which allows you to include aggregate functions in an expression and use them on a data source level.

UnboundExpressionMode.UseAggregateFunctions The UnboundExpressionMode.UseAggregateFunctions mode introduces a specified set of aggregate functions (Sum, Min, Max, etc.). These functions can be used to perform summary calculations on a data source level.

The following example illustrates the margin calculation. The sum of Profit values is divided by the sum of ExtendedPrice values.

Note

If you enable the UnboundExpressionMode.UseAggregateFunctions mode, the Aggregate function group appears in the Expression Editor.

UnboundExpressionMode.Default The UnboundExpressionMode.Default setting indicates that the PivotGridOptionsData.DataFieldUnboundExpressionMode property value specifies the calculation mode. This setting allows you use the Pivot Grid's global option to control how unbound fields are calculated.

Expanded Enable End-Users to Edit Expressions

End-users can use the Expression Editorto edit unbound field expressions. To make this editor available to users, set the PivotGridFieldOptionsEx.ShowUnboundExpressionMenu property to true. This adds the Expression Editor... command to a field's context menu.

In code, use the PivotGridControl.ShowUnboundExpressionEditor method to invoke the editor.

Use the PivotGridOptionsBehavior.ExpressionEditorMode property to specify the Expression Editor’s version.

Expanded See Also

Is this topic helpful?​​​​​​​