[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
  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]Get Started With Data Grid and Views
   [Expand]Data Binding
    Unbound Columns
   [Expand]Views
   [Collapse]Data Editing and Validation
    [Expand]ErrorInfo Support
     Add and Remove Rows
     Cell Values, Editors, and Validation
   [Expand]Grouping
   [Expand]Sorting
   [Expand]Filter and Search
   [Expand]Summaries
   [Expand]Focus and Selection Handling
    Format Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
    Split Presentation
    Row Preview Sections
   [Expand]Scrolling
   [Expand]Batch Modifications
    Hit Information
    Hints
    Popup Menus
   [Expand]Save and Restore Layout
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]Examples
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [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]Sunburst 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]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Cell Values, Editors, and Validation

Cell Values

Cell Editors

Edit Data in a Separate Form

Manage End-User Input

Expanded Read and Modify Cell Values in Code

Processed Cell

Read the Cell Value

Change the Cell Value

A focused cell

ColumnView.GetFocusedValue
ColumnView.FocusedValue

ColumnView.SetFocusedValue

A cell of a focused row

ColumnView.GetFocusedRowCellValue
ColumnView.GetFocusedRowCellDisplayText

ColumnView.SetFocusedRowCellValue

Any row cell

ColumnView.GetRowCellValue
ColumnView.GetRowCellDisplayText

ColumnView.SetRowCellValue

A cell value in an underlying data source

ColumnView.GetListSourceRowCellValue

A currently edited cell

ColumnView.EditingValue

ColumnView.EditingValue

Changing a cell value raises the ColumnView.CellValueChanged event.

The following code samples illustrate this API.

The code below retrieves the value of a cell that belongs to the "ID" column and the third data row (row handle equals 2).

This code returns the text displayed inside the currently focused cell.

This example changes the value of the focused cell.

Grid cell editors wait for a user to move focus to another cell or row before their new value is accepted. The code below forces editors to immediatelly update their values.

In the Change column cell values based on other cell values demo checkboxes under the "Mark" column are automatically checked if you enter "Length" more than 10, and cleared otherwise.

Expanded Cell Editors

Default Cell Editors

Data Grid supports in-place data editing out-of-the box. To edit a cell value at runtime, an end-user must focus it and press Enter, or double-click this cell. To discard edits, press Esc while editing.

Columns utilize DevExpress Editors to display and edit data source records. Columns automatically choose editors depending on the column data type. For instance, if a column displays dates, it will utilize the DateEdit in-place editor.

All DevExpress Editors contain related repository items. For instance, a SpinEdit editor contains a RepositoryItemSpinEdit object. Repository items are cores that store a set of properties required to generate a fully-fledged editor. You can access an editor's repository item through the BaseEdit.Properties property.

All inactive Grid cells contain repository items. When a user clicks a cell to edit its value, a real editor is created from this repository item. After all edits are done and the cell is deselected, its editor is destroyed again. This means unless Grid is in edit mode, no fully initialized cell editors exist. This technique greatly improves the Data Grid performance.

Demos: Inplace Cell Editors | Show buttons in grid cells

Replace Default Cell Editors at Design Time

To modify an in-place editor for a Data Grid column, invoke drop-down menu for the GridColumn.ColumnEdit property and create a new editor (or choose an existing one). This property can be accessed from the column smart tag.

The "In-place Editor Repository" tab of a Data Grid Designer provides a centralized access to all in-place editors. Here you can add new editors, as well as modify and remove existing ones.

Replace Default Cell Editors in Code

To use custom editors for column cells, assign related repository items to the GridColumn.ColumnEdit property. The Assign in-place editors (repository items) demo illustrates how to replace standard checkboxes for the "Mark" column with ToggleSwitch editors.

If you need to specify an in-place editor for a specific cell rather than an entire column, handle the GridView.CustomRowCellEdit event. Note that any repository item you create in code must be manually added to the grid control's EditorContainer.RepositoryItems collection.

The code below illustrates how to utilize a ProgressBarControl as an in-place editor for the integer "Relevance" grid column. End-users can tap or hold numpad "+" and "-" keys to modify these integer values.

The Cell commands to edit and delete rows demo has the "Commands" column with a ButtonEdit cell editor. The editor has two buttons: "Edit" invokes the Edit Form, "Delete" removes the current row.

In the Assign in-place editors dynamically demo the "Length" column receives either a SpinEdit or a CalcEdit editor depending on whether the checkbox under the "Mark" column is checked.

The code sample below creates two identical RepositoryItemButtonEdit editors with buttons that copy or remove a cell value. The second editor buttons are disabled. If a checkbox under the "Mark" column is currently checked, an editor with enabled buttons becomes this cell's editor. Otherwise, when the "Mark" checkbox is clear, the editor with disabled buttons is assigned.

Demos: Assign in-place editors (repository items) | Assign in-place editors dynamically

Use Any Control as a Cell Editor

The RepositoryItemAnyControl allows you to embed any static control into a grid cell. The figure below illustrates an embedded Chart Control.

In order to embed a control, it must implement the DevExpress.XtraEditors.CustomEditor.IAnyControlEdit interface. The Gauge Control implements this interface out-of-the-box. To embed other controls, you need to implement it manually.

Embedded Gauge Control: Demo | Example

Embedded Chart Control: Demo | Example

Use Different Controls to Display and Edit Cell Values

By default, in-place editors are used for both presenting data and editing records. If needed, you can use separate in-place editors for both tasks. To do so, handle the GridView.CustomRowCellEditForEditing event. In the code sample below, a numeric column utilizes ProgressBarControl in-place editors to display data. When end-users focus cells, SpinEdit editors replace progress bars, which provide a more straightforward way of modifying cell values.

Demo: Override the default in-place editor for certain cells

Manage Cell Editors in Code

API

Description

BaseView.ShowEditor

Invokes the focused cell's editor

BaseView.HideEditor

Closes the currently active editor and discards any changes

BaseView.CloseEditor

Saves any changes made and closes the currently active editor

BaseView.PostEditor

Saves any changes made without closing the currently active editor

BaseView.ActiveEditor

Retrieves the currently active editor

ColumnView.ShownEditor

Fires whenever an in-place editor activates. The code below automatically sets the current date and opens the DateEdit popup when end-users activate the "Order Date" column editor.

ColumnView.HiddenEditor

Fires whenever an in-place editor closes. In the sample below, focus automatically moves to the cell below after an editor for the current cell closes. This allows your end-users to quickly change values of multiple cells that belong to the same column by entering new values and pressing Enter (or Escape). This code will not be executed when end-users work with a New Item Row.

Expanded Edit Data in a Separate Form

Edit Form

Instead of in-place data editing, end-users can modify grid records by using an Edit Form. To invoke this form, double-click a grid row at runtime or press the Enter or F2 key.

For regular Views you can select one of three available Edit Form display modes:

  • a floating modal form (default mode);
  • an in-place form displayed below a grid row that is being edited;
  • an in-place form displayed instead of the edited row.

Detail Views do not support in-line edit forms.

Related API

API

Description

GridOptionsBehavior.EditingMode

Allows you turn on the Edit Form and select its display mode.

GridView.ShowEditForm
GridView.HideEditForm

Call these methods to manually display and hide an Edit Form.

GridOptionsEditForm.ActionOnModifiedRowChange

Specifies whether to show confirmation dialogs when end-users modify records.

GridOptionsEditForm.ShowUpdateCancelPanel

Gets or sets whether or not the "Update" and "Cancel" buttons should be displayed. When these buttons are hidden, end-users can still utilize hotkeys to save (Ctrl+Enter) or discard (Escape) changes.

GridOptionsEditForm.BindingMode

Specifies whether to pass changes to a Data Grid immediately after an end-user moves focus to another Edit Form field, or only after all changes have been accepted.

GridOptionsEditForm.FormCaptionFormat

Allows you to modify a caption of a floating Edit Form.

GridView.EditFormShowing

Fires when the Edit Form is about to be shown, and allows you to forcibly hide the Edit Form when you do not want users to edit specific cell values. In the Prevent the Edit Form from Showing demo you cannot edit odd rows.

Demos: Inline Edit Form | Prevent the Edit Form from showing | Access an editor within the Edit Form

Access Editors in the Edit Form

When an Edit Form is initialized and is about to be shown, the GridView.EditFormPrepared event raises. You can handle this event to access any Edit Form editor and modify its settings. The Access an Editor Within the Edit Form demo illustrates how to find the DateEdit editor and focus it.

Modify Edit Form Layout

Default Edit Form layout is built according to the following rules:

  • Edit Form displays an editor for every visible editable column;
  • in case a Grid Column uses different editor types to present and edit cell data, Edit Form utilizes ones that are used in editing records;
  • an Edit Form client area has a table layout with three columns; every editor (except for MemoEdit and PictureEdit editors) occupies one single cell;
  • MemoEdit editors span across all layout columns horizontally and three layout rows vertically;
  • PictureEdit editors span across two layout columns horizontally and three layout rows vertically.

To modify this default layout, invoke the Data Grid Designer and switch to its "Edit Form Designer" tab. Here you can modify layout settings of every column editor.

Related API

API

Description

GridColumn.OptionsEditForm

Provides access to layout settings that affect how an editor for this specific column looks within an Edit Form (see below).

OptionsColumnEditForm.UseEditorColRowSpan

Disable this setting to set custom column and row spans for an editor.

OptionsColumnEditForm.ColumnSpan
OptionsColumnEditForm.RowSpan

Specify the number of Edit Form columns and/or rows across which an editor stretches.

OptionsColumnEditForm.Caption
OptionsColumnEditForm.CaptionLocation

Allow you to modify the editor caption and its relative position.

OptionsColumnEditForm.Visible
OptionsColumnEditForm.VisibleIndex

Use these properties to hide and re-arrange column editors.

OptionsColumnEditForm.StartNewRow

Set this option to true to move the editor to a new row.

Create Custom Edit Forms

You can create your own User Control and utilize it instead of a default Edit Form.

  1. Create a User Control and inherit it from the EditFormUserControl class.
  2. If you have partial classes for this User Control, they must inherit the EditFormUserControl class as well.
  3. Design your custom User Control UI.
  4. Use the BoundFieldName and BoundPropertyName extender properties provided by the parent class to bind editors to data source fields.
  5. Assign an instance of the custom edit form to the Data Grid GridOptionsEditForm.CustomEditFormLayout property.
  6. To be able to use this custom form in detail Views, assign separate form instances to each detail View.

Demos: Custom Edit Form | Inline Edit Form

Tip

You can also use a custom form to edit data. See how to implement a custom form in the Implementing CRUD operations in read-only data sources using XtraGrid KB article.

Expanded Manage End-User Input

Use Masks to Limit Data Input

Since DevExpress editors support Masks, you can prevent a user from entering invalid characters. The sample below illustrates how to allow users to enter 10-digit phone numbers with the automatically added "+1" country code.

Make Certain Grid Cells Non-Editable

To prevent users from editing cell values at runtime, utilize one of the following approaches:

  • disable the ColumnViewOptionsBehavior.Editable option;
  • enable the OptionsColumn.ReadOnly setting;
  • disable the OptionsColumn.AllowEdit and OptionsColumn.AllowFocus options;
  • handle the ColumnView.ShowingEditor event and set its Cancel parameter to true. For instance, the code snippet below prohibits editing records whose "Country" field equals "Germany".

You can also check the Read-only mode for certain cells demo where you cannot edit the "ID" column cells for every even row.

These settings affect only your end-users and do not prevent you from modifying cell values in code.

Demos: Non editable mode | Prohibit editing certain GridView's cells

Validate Cell Values

A cell is validated when a user has finished editing a value and presses Enter or moves focus to another cell within the same row. You can also forcibly trigger validation by calling the BaseView.PostEditor method in code. The diagram below illustrates this validation process.

  • BaseView.ValidatingEditor - handle this event to check whether or not a new cell value is correct and set the boolean e.Valid parameter accordingly. End-users are unable to leave a cell with an incorrect value until the error is fixed or the "Esc" key is pressed to undo changes.

  • BaseView.InvalidValueException - raises if the e.Valid parameter of the previous event has been set to false and allows you to specify how the Data Grid responds to an invalid value. See the ExceptionMode enumerator values to see what options are available.

  • If the ExceptionMode parameter is set to NoAction, cells do not accept invalid values without notifying users. Use this approach if you want to implement custom notifications. For instance, you can provide default error icons for multiple columns at once by calling the ColumnView.SetColumnError method.

The code sample below checks the order shipping date, which cannot be earlier than the date this order was placed.

The Data Validation demo utilizes a different cell validation approach and employs the GridView.RowCellStyle event to highlight cells with values that are wrong initially, not after an end-user has modified them.

Demos: Data Validation | Validate the active editor's value

Validate Rows

With the row validation feature, the Data Grid delays checking cell values to the point when a user moves focus to another row. This can be useful when each particular cell is valid, but the entire row with these values is incorrect. To manually trigger row validation, call the ColumnView.UpdateCurrentRow method.

  • ColumnView.ValidateRow, ColumnView.InvalidRowException - similar to per-cell validation, these events allow you to validate new cell values and respond to invalid ones. If new cell values do not pass validation, end-users are kept on the current row to either correct all errors, or press Esc and undo the changes. Note that to revert row cell values back to correct ones, data source objects must implement the IEditableObject interface.

  • If a row is invalid, the Data Grid displays a message by default, permitting users to either correct or discard new values. You can suppress this default notification and call the ColumnView.SetColumnError method to manually mark specific cells (or the entire row) as invalid.

In the Data Validation demo, the ValidateRow event is handled to calculate values of the "Sub Total" column cells based on the "Unit Price", "Quantity" and "Discount" column cells. Negative subtotal values are not accepted.

Demos: Data Validation | Validate row data on losing focus

Expanded See Also

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