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
   [Expand]Data Binding
   [Expand]Views
   [Collapse]Data Editing and Validation
    [Expand]ErrorInfo Support
     Add and Remove Rows
     Modify and Validate Cell Values
   [Expand]Grouping
   [Expand]Sorting
   [Expand]Filter and Search
   [Expand]Summaries
   [Expand]Focus and Selection Handling
    Formatting Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
    Split Presentation
    Row Preview Sections
    Scrolling
   [Expand]Batch Modifications
   [Expand]Hit Information
    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]ASP.NET Core 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]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Modify and Validate Cell Values

In-Place Editors

Edit Form Manage End-User Input

Expanded Default In-Place Editors

Data Grid columns utilize DevExpress Editors, and optionally, more complex DevExpress controls 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. To invoke an in-place editor and modify a record, an end-user must double-click a cell or focus it, and press Enter or Space.

Demos: Inplace Cell Editors | Show buttons in grid cells

Expanded Change Default In-Place 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.

Expanded Change Default In-Place Editors in Code

DevExpress editors have corresponding repository items - objects that store main editor properties. A repository item is a core from which a full editor can be generated. For instance, a RepositoryItemSpinEdit object is the core of a SpinEdit editor. For in-place editing in the Data Grid, you need to create these repository items and assign them to GridColumn.ColumnEdit properties. Alternatively, if you need to specify an in-place editor for a specific cell, and not 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. To test this code sample, run the Dynamically Assigned Editors demo.

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

Expanded Use Non-Editor Controls as In-Place Editors

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

Expanded Display and Edit In-Place Editors

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

Expanded Manage In-Place Editors in Code

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.

BarEditItemLink.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 Retrieve and Modify Cell Values in Code

To retrieve cell values, utilize the following API.

The API below allows you to change cell values in code.

The following code sample illustrate this API.

Example 1: Get values of the "ID" column within the third data row (row handle equals 2).

Example 2: Obtain text of a focused cell.

Example 3: Obtain the value of a cell that belongs to the focused row and the first column.

Example 4: Change the focused cell's value.

Example 5: Set the value of a cell that belongs to the focused row and the first Data Grid column.

Expanded 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

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

Expanded 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

Expanded Custom Edit Form

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. Design your custom User Control UI.
  3. Use the BoundFieldName and BoundPropertyName extender properties provided by the parent class to bind editors to data source fields.
  4. Assign an instance of the custom edit form to the Data Grid GridOptionsEditForm.CustomEditFormLayout property.
  5. 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

Expanded Prevent End-Users from Modifying Cell Values

To disable the editing of 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".

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

Expanded Validate End-User Input (Per Cell)

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

Expanded Row Validation

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
    Similarly 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

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