Add Unbound Data to a Data-Aware Control (XtraGrid, XtraPivotGrid)
- 3 minutes to read
In most cases data-aware DevExpress .NET controls contain bound columns/fields that display data from bound data sources. In Grid Control and PivotGrid controls, it is possible to add unbound columns/fields that can display arbitrary data. Unbound columns are not bound to any field in a data source. You can provide data for these fields by specifying a formula (string expression) used to evaluate values or by handling an event
If you want to bind data without the currently existing ready-to-use source, use the UnboundSource component.
An unbound column/field must meet the following two requirements:
- its FieldName property must be set to a unique value and not refer to any field in the control's data source;
- its UnboundType property must be set to an appropriate value according to the type of data the column/field is supposed to display (Boolean, DateTime, Decimal, Integer, String or Object). It should not be set to an UnboundColumnType.Bound value. This property determines which default editor will be used to represent the column's values, how the values of the cells will be aligned, and which sorting and validity rules should be applied to the column, etc.
There is no difference between working with bound and unbound columns/fields. Unbound columns can be sorted, grouped and filtered in the same manner as bound columns. They also support summaries. When printing or exporting a control, the contents of unbound columns will be printed/exported as well.
Providing data using expressions
For an unbound column/field, you can specify a formula (string expression) that will be used to evaluate values for this field. Use the column's UnboundExpression property to specify an expression. At design time, you can invoke an Expression Editor via the Property Grid to build the expression. The Expressions section describes a syntax for creating formulas in code.
Expressions do not allow data entered by end-users to be saved. To create unbound columns and allow data entered by end-users to be saved, you need to provide data for unbound columns using an event (see below).
Providing data via an event
A specific event fires for unbound columns/fields, allowing data to be provided. In addition, in the Grid Control, this event allows data entered by an end-user to be saved. In the Grid Control control, use the ColumnView.CustomUnboundColumnData event. In the PivotGrid control, use the PivotGridControl.CustomUnboundFieldData event. These events are raised for each cell within unbound columns/fields.
- How to: Add an Unbound Field to Supply Additional Data
- How to: Add an Unbound Field to Change Axis Detailing
- How to: Provide Data for an Unbound Field Using Expressions