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

Tutorial: Unbound Columns

This walkthrough is a transcript of the Unbound Columns video available on the DevExpress YouTube Channel.

In this tutorial, you will learn how to add columns whose values are not stored in the data source and are calculated using a pre-defined expression or specified with an event handler. You'll also see how you can provide separate storage for values displayed in these unbound columns.

Data for the unbound columns will be calculated based on values of the Quantity, UnitPrice and Discount columns.

Expanded Creating Unbound Columns and Specifying Expressions for them at Design Time

Select a grid control and then click its smart tag. Click Add Column twice to create two new columns.

Resize the columns to make them wider. Click the first created column and set its GridColumn.FieldName to a unique string: "DiscountAmount".

Then, set the column's GridColumn.UnboundType property to any value other than UnboundColumnType.Bound. The column will display decimal values in this case.

Use the GridColumn.UnboundExpression property to specify an expression used to calculate column values. Click the ellipsis button to open the Expression Editor, which will allow you to create formulas using various functions, operators, data field values, and constants. Create a simple expression that multiplies three existing fields.

To make this unbound column read-only, set the OptionsColumn.AllowEdit property to false.

Now format the values of the two columns as currency. Hold down the CTRL or SHIFT key and click another column. This selects two columns simultaneously. In the Properties grid, expand GridColumn.DisplayFormat and set FormatInfo.FormatType to FormatType.Numeric and FormatInfo.FormatString to c2.

Run the application. The first column displays calculated data and formats it as currency.

Expanded Editing Expressions for Unbound Columns at Runtime

It is possible to allow an end-user to modify expressions for unbound columns at runtime. To accomplish this, set the column's GridColumn.ShowUnboundExpressionMenu property to true.

The column's context menu now provides the Expression Editor... command. When it's invoked, the Expression Editor dialog opens allowing you to modify the expression.

Expanded Providing Data for Unbound Columns Using an Event

For the second column, whose data will be provided later using an event, we also need to specify a unique GridColumn.FieldName and set its GridColumn.UnboundType property to UnboundColumnType.Decimal.

Supply values for the second unbound column by handling a dedicated event. Select gridView1 and switch to the Events page in the Properties grid. Subscribe to the ColumnView.CustomUnboundColumnData event.

The ColumnView.CustomUnboundColumnData event fires each time a column value is about to be displayed onscreen, and also after a column cell is modified and data posting is required. Values for the Total column will be calculated from Quantity, UnitPrice and Discount column values. First, you need to retrieve these values using methods of the bound data source. The grid control provides a helper ColumnView.GetListSourceRowCellValue method to do this. Second, calculate a value for the unbound column and assign it to the CustomColumnDataEventArgs.Value event parameter.

Run the application. The Total column displays data provided by the event handler.

This column is not read-only. Therefore, you can modify cells, but the changes will not be saved.

Expanded Implementing Data Posting for Unbound Columns

The data grid does not store or cache values of unbound columns. It's up to you to implement data posting. To illustrate the data posting feature, modify the code.

In this code, values for the Total column are stored in a dictionary. When an end-user modifies a cell, the ColumnView.CustomUnboundColumnData event fires and its CustomColumnDataEventArgs.IsSetData parameter equals to true. The new value is saved in the dictionary for later use.

Run the application again. Try modifying values to confirm that the changes were saved.

Expanded See Also

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