Skip to main content

Unbound Fields

  • 2 minutes to read

#Bound and Unbound Fields

Pivot Grid supports bound and unbound fields. Bound fields obtain their data from the corresponding fields in a data source. Unbound fields are not bound to any field in the data source. These fields must be populated manually.

An unbound field is one that meets the following two requirements:

  • The PivotGridField.FieldName property must be set to a unique value, and must not refer to any field in the pivot grid's data source.
  • The PivotGridField.UnboundType property must be set to an appropriate value according to the type of data this field is supposed to display (Boolean, DateTime, Decimal, Integer, String or Object). This property also determines an unbound field's default editor, used to represent its values.

#Providing Data for Unbound Fields

In most instances, data for unbound columns is obtained from a custom data source, or calculated based on the values of bound columns. You can handle the PivotGridControl.CustomUnboundFieldData event or specify an expression (formula) used to evaluate values for this field via the PivotGridField.UnboundExpression property. The Expressions section describes the syntax for creating expressions.

In the pivot grid, an expression can be calculated against the summary values, or data source records. In the second instance, the expression is calculated against each data source record, and then the resulting values are summarized. Use the PivotGridControl.DataFieldUnboundExpressionMode property to specify how unbound expressions are calculated.

#Example: How to Display Unbound Data

This example shows how to add an unbound field to the PivotGridControl, to represent the total sum of an order.

Assume that the PivotGridControl is bound to the Order Details datatable (from the nwind sample database), which contains UnitPrice, Quantity and Discount fields. There isn't any field which represents the total sum, however this can be calculated manually as follows: "UnitPrice*Quantity*(1-Discount)".

To solve this task, first it is necessary to create a pivot grid field, whose PivotGridField.UnboundType property should be set to FieldUnboundColumnType.Decimal. Then, you should handle the PivotGridControl.CustomUnboundFieldData event and manually populate the field with data.