[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Implementation Details
   [Expand]Views
   [Expand]Grid View Data Layout
   [Expand]Binding to Data
   [Expand]Master-Detail Data Representation
   [Collapse]Data Editing and Validation
     Add and Remove Rows
    [Collapse]Modify Cell Values
      Obtain and Set Cell Values in Code
      In-place Editors
      Edit Form
    [Expand]Input Validation
    [Expand]Clipboard Management
     Examples
   [Expand]Grouping
   [Expand]Selection
   [Expand]Filtering and Searching
   [Expand]Sorting
   [Expand]Data Summaries
   [Expand]Paging and Scrolling
   [Expand]Focus and Navigation
   [Expand]Conditional Formatting
   [Expand]Drag-and-Drop
   [Expand]Appearance Customization
   [Expand]MVVM Enhancements
   [Expand]Printing and Exporting
   [Expand]End-User Interaction
   [Expand]Miscellaneous
   [Expand]Performance Improvement
   [Expand]Design-Time Features
   [Expand]Visual Elements
   [Expand]End-User Capabilities
   [Expand]Examples
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[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)

In-place Editors

The GridControl allows you to edit cell values using in-place Data Editors:

Expanded Availability

Data editing is allowed if the DataViewBase.AllowEditing property is set to true and the DataViewBase.NavigationStyle property is set to GridViewNavigationStyle.Cell.

Individual columns provide the ColumnBase.AllowEditing property. The property's default value is Default - the View controls the column's behavior. Set this property to true or false to override the default behavior. For example, you can set the column's ColumnBase.AllowEditing property to false to prevent an end user from changing its values.

If the column's ColumnBase.ReadOnly property is set to true:

  • End users cannot modify the column's cell values (they can invoke cell editors, select and copy their values).
  • You can change cell values in code using the GridControl.SetCellValue method.

If the View is in edit mode, the DataViewBase.ActiveEditor property returns the edited cell's editor and the DataViewBase.IsEditing property returns true.

Expanded Assign Editors to Columns

The GridControl automatically creates an editor for a column based on its value type. For example, if a column is bound to a DateTime field, the GridControl creates a date editor for it. If a column is bound to a numeric field, the numeric editor is used. Otherwise, the text editor is used.

Each editor has a helper class responsible for the editor's functionality:

Use the column's ColumnBase.EditSettings property to specify an in-place editor for a column. The following code sample shows how to assign a spin editor to the UnitPrice column:

When the same editor is used in multiple locations, the GridControl uses the helper class to paint its cells. The actual editors are only created when end users start to edit a cell and are automatically destroyed when editing is completed. This improves the application's performance.

To obtain a column's actual editor, use the ColumnBase.ActualEditSettings property. This property returns the editor's helper class that is responsible for the editor's functionality and behavior.

Tip

The GridControl provides the Smart Columns Generation feature. When this feature is enabled, the GridControl automatically creates the layout and configures data editors for all generated columns according to data types, Data Annotations and DevExpress Fluent API attributes specified in the underlying data source.

Expanded Cell Templates

You can use the ColumnBase.CellTemplate / DataViewBase.CellTemplate to define data cells' presentation. These templates allow you to:

  • Specify settings that an editor's helper class does not have.
  • Provide different settings to editors in the same column.
  • Create a custom editor.

Display and Edit Templates

In-place editors are used for both presenting data and editing records. You can use separate in-place editors for both tasks. Each column provides two templates that allow you to define custom editors that display (when the grid is in browse mode) and/or edit (when the grid is in edit mode) column values:

Template Description
ColumnBase.CellDisplayTemplate / DataViewBase.CellDisplayTemplate Defines a template that displays column values.
ColumnBase.CellEditTemplate / DataViewBase.CellEditTemplate Defines a template that represents an editor used to edit cell values.

End Users' Actions

The GridControl provides the following events to process end users' actions:

Event Description
DataViewBase.GetIsEditorActivationAction Allows you to specify whether an action (key down, text input, or mouse left button click) activates the focused editor.
DataViewBase.ProcessEditorActivationAction Allows you to process actions that activate the focused editor.
DataViewBase.GetActiveEditorNeedsKey Allows you to specify whether an active editor responds to keys an end user presses.

Expanded Show and Hide Editors in UI

An end user can switch the GridControl to edit mode in the following ways:

  • Click the required cell
  • Press Enter
  • Press F2
  • Start typing.

This activates the focused cell's in-place editor to allow an end user to modify the value.

To save the changes and close the editor, an end user should press Enter or move the cell focus to another cell. Pressing Esc closes the editor and discards the changes.

Expanded Show and Hide Editors in Code

Show Editors

To invoke the cell's editor in code, you should focus the cell and call the DataViewBase.ShowEditor method. Refer to Focusing Cells and Moving Row Focus for information on how to move cell and row focus.

The GridViewBase.ShowingEditor / TreeListView.ShowingEditor events are raised before the focused cell's editor is activated. These events allow you to cancel the action and prevent its value from being edited. After the editor has been shown, the GridControl raises the GridViewBase.ShownEditor / TreeListView.ShownEditor event.

Hide Editors

The GridControl provides two methods to hide the active editor:

Method Description
DataViewBase.CloseEditor Hides the active editor and saves the changes.
DataViewBase.HideEditor Hides the active editor and discards the changes.

To save changes to a data source without closing the active editor, use the DataViewBase.PostEditor method.

Before the active editor's new value is posted to a data source, it is validated. If a new value is valid, it is posted to a data source and the editor can be closed. Otherwise, if a new value is invalid, the active editor cannot be closed, and cell focus cannot be moved to another cell until its value is correct. Refer to the Cell Validation topic for more information.

After the editor has been closed, the GridControl raises the GridViewBase.HiddenEditor / TreeListView.HiddenEditor event.

Expanded Immediate Posting

After a cell has been edited, an end user should unfocus the cell to post the cell's value to a data source. You can make the GridControl post values to a data source after an end user changes a cell's value.

Approach 1

Set the DataViewBase.EnableImmediatePosting property to true.

Approach 2

Handle the GridViewBase.CellValueChanging event and call the DataViewBase.PostEditor method in the event handler. Use this approach if you need to implement complex logic.

The following code sample posts the Name column's values:

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