Skip to main content

Showing and Hiding Editors

  • 2 minutes to read
NOTE

End-users can invoke cell editors and change cell values if the view's DataViewBase.AllowEditing property is set to true and the DataViewBase.NavigationStyle property is set to GridViewNavigationStyle.Cell.

End-users can switch a grid to edit mode by clicking a required cell or pressing the ENTER or F2 key. This activates a focused cell's in-place editor, allowing a user to modify the focused cell's value. To save these changes and close the editor, an end-user should press ENTER, or move cell focus to another cell. Pressing ESC closes the editor, discarding all the changes made.

Cell editors can also be activated and closed in code.

#Showing Editors

To programmatically activate a cell's editor, you should focus a cell and call the DataViewBase.ShowEditor method. This method raises the GridViewBase.ShowingEditor event, allowing you to prevent showing editors for individual cells, thus preventing their values from being edited. After an editor has been shown, a View fires the GridViewBase.ShownEditor event.

#Example: How to Prevent Individual Data Cells From Being Edited

For information on how to move cell and row focus, see Focusing Cells and Moving Row Focus.

#Hiding Editors

There are two methods that hide the active editor. The DataViewBase.CloseEditor method hides the active editor, saving the changes made. The DataViewBase.HideEditor method hides the active editor and discards the changes. To save changes to a data source without closing an active editor, use the DataViewBase.PostEditor method.

Before an 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 corrected. To learn more, see Validating Editors.

After an editor has been closed, a View fires the GridViewBase.HiddenEditor event.