Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[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
  [Collapse]Data Grid
   [Expand]Getting Started
   [Collapse]Binding to Data
    [Expand]Server Mode
     Grid Control Binding Specifics
     Posting Data to a Connected Database
     Unbound Columns
     Binding to Entity Framework Models
     Binding via Data Source Configuration Wizard
     Fluent API Support
     Member Table: Data Binding
     Tutorial: ADO.NET Data
     Tutorial: Create and Manage Columns at Design Time
     Tutorial: Create and Manage Data in Code and Apply Data Annotation Attributes
     Tutorial: Entity Framework Data
     Tutorial: Unbound Columns
     Tutorial: Working with Columns in Code
   [Expand]Grid View
   [Expand]View Technology
   [Expand]Grouping
   [Expand]Sorting
   [Expand]Summaries
   [Expand]Data Editing
   [Expand]Filtering and Locating Rows
   [Expand]Focus and Selection Handling
   [Expand]Processing Rows
   [Expand]Formatting Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
   [Expand]Batch Modifications
   [Expand]Hit Information
   [Expand]Hints
   [Expand]Popup Menus
   [Expand]Saving and Restoring Layouts
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]Examples
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [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]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Unbound Columns

This page covers unbound columns that help display custom data within the Grid Control. These columns are not bound to fields in the data source, thus data for these columns needs to be provided using expressions or a dedicated event.

 

Expanded Online Video

Learn how to add columns whose values are not stored in the data source, but are instead calculated using a pre-defined expression or specified by an event handler.

Expanded Bound and Unbound Columns

There are two types of columns in Grid Control Views: bound and unbound.

Bound columns obtain their data from a grid's data source, which is specified by the GridControl.DataSource and GridControl.DataMember properties. These columns' GridColumn.FieldName properties refer to valid fields in the data source.

In certain cases, the data source does not provide the values you wish to display in a View. For instance, you may want to display a column whose values are calculated according to a formula based on values of other columns. Or you may want to display values in this column from a different data source. All these cases can be addressed by creating an unbound column. Data for this column needs to be specified manually, using one of the following two approaches.

  • By specifying a formula (string expression) using the GridColumn.UnboundExpression property used to automatically evaluate values for this column. Expressions allow you to calculate values based on values of other columns. You can use constants, various functions and operators in expressions. See Expressions to learn about the syntax.
  • By handling the ColumnView.CustomUnboundColumnData event. In this event, you can implement custom logic of any complexity.

    With this event, you can enable an end-user to edit values in unbound columns. When an end-user modifies a cell, the CustomUnboundColumnData event fires, allowing you to save changes.

    Note

    The CustomUnboundColumnData event fires only for visible unbound columns.

To create an unbound column, add a GridColumn object to the View's ColumnView.Columns collection and set the following column properties.

Property Description
GridColumn.FieldName Set this property to a unique string. This value must not match field names of other columns and it must not match field names existing in the grid control's underlying data source.
GridColumn.UnboundType Set this property to a value that identifies the type of data the column is supposed to display (Boolean, DateTime, Decimal, Integer, String or Object). Do not set the column's UnboundType property to UnboundColumnType.Bound, as this would identify the column as bound.

An unbound column's GridColumn.UnboundType property determines which default editor is used to represent column values. For example, if the GridColumn.UnboundType property is set to UnboundColumnType.DateTime, the column will use a DateEdit in-place editor. Second, this property's setting determines how cell values are aligned, and which sorting and validity rules are applied to the column.

Note that you can explicitly assign a specific editor to a column with the GridColumn.ColumnEdit property and to a specific cell by handling the GridView.CustomRowCellEdit event.

After the column is created, implement logic for populating it with data, as described in the following section.

Expanded Unbound Columns' Data

You can provide data for unbound columns either by creating an expression using the GridColumn.UnboundExpression property or by handling the ColumnView.CustomUnboundColumnData event. To learn about the syntax of expressions, see Expressions.

At runtime, an end-user can edit an unbound column's expression using an Expression Editor. The latter can be opened using a context menu (if the GridColumn.ShowUnboundExpressionMenu option is enabled) or in code using the ColumnView.ShowUnboundExpressionEditor method.

By default, data editing is enabled in unbound column cells. However, you may wish to prevent an end-user from editing unbound columns. To make a column read-only, the OptionsColumn.AllowEdit or OptionsColumn.ReadOnly options can be used.

If you wish to save the changes made by end-users in unbound columns, an unbound column should be populated with the ColumnView.CustomUnboundColumnData event, but not using expressions. This event's IsGetData and IsSetData parameters determine the event's current mode of operation. If the IsGetData parameter is set to true (and consequently the IsSetData parameter is set to false), the event handler should supply data for an unbound column. A value should be assigned to the Value parameter according to the row currently being processed. The current row can be identified using the ListSourceRowIndex parameter, which specifies the row's index in a grid's data source. It is not affected by any sorting or filtering settings.

If the IsSetData parameter is set to true (and consequently the IsGetData parameter is set to false), the event has been fired as a result of data modifications within a grid. In this case, the Value parameter contains modified data and should be stored for further use.

Note

If you need to get or set specific cell values while handling the CustomUnboundColumnData event, use methods provided by the bound data source. The event's ListSourceRowIndex parameter allows you to identify the current data row.

Do not use methods provided by a View object (for example, ColumnView.GetRowCellValue, ColumnView.SetRowCellValue, etc.) to get/set cell values in a CustomUnboundColumnData event. These methods take row handles as parameters. However, the CustomUnboundColumnData event may be called when a View object has not been initialized. In this instance, row handles are not initialized properly. Calling these methods may also result in recursive calls to the event.

Expanded Working with Unbound Columns

There is no difference between working with bound and unbound columns. Unbound columns can be sorted, grouped and filtered in the same manner as bound columns. They also support summaries.

However, please keep in mind those situations in which unbound columns retrieve their data from a custom data source, and a record is added to or deleted from the grid's main data source. When a record is added, you usually need to add a new entry to the custom data source that corresponds to the new record in the grid. Similarly, when a record is deleted you usually need to delete the corresponding entry in the custom data source. To receive notifications about a record that has been added or removed, use the methods provided by the data source.

When printing or exporting a grid, the contents of the unbound columns will be printed/exported as well.

Note that the Grid Control cannot operate with only unbound columns (without binding the control to a data source using the GridControl.DataSource and GridControl.DataMember properties).

To override the default display values in a column with custom ones, handle the ColumnView.CustomColumnDisplayText event, which is in effect both for bound and unbound columns.

Expanded Example - Implement Unbound Columns Via Event

Assume that the Grid Control is bound to a table that contains the "Quantity", "UnitPrice" and "Discount" columns. The example below shows how to add an unbound column to the grid to display the amount of each order according to the expression: Quantity*UnitPrice*(1-Discount).

The result is displayed below:

For another example which illustrates working with unbound columns, see the Unbound Columns tutorial.

Expanded Example - Implement Unbound Columns Using Expressions

The following code shows how to create an unbound column (Ext Price) and populate it with data using expressions. Data for this column is calculated according to the formula: [Quantity] * [UnitPrice] * (1 - [Discount]), which is set via the GridColumn.UnboundExpression property.

Expanded See Also

How would you rate this topic?​​​​​​​