dotnetmonitor.com

 
Index
Previous
Next

 

By default, users can edit the contents of the current DataGridView text box cell by typing in it or pressing F2. This puts the cell in edit mode if all of the following conditions are met:

 

  • The underlying data source supports editing.
  • The DataGridView control is enabled.
  • The EditMode property value is not EditProgrammatically.
  • The ReadOnly properties of the cell, row, column, and control are all set to false.

 

In edit mode, the user can change the cell value and press ENTER to commit the change or ESC to revert the cell to its original value.

 

You can configure a DataGridView control so that a cell enters edit mode as soon as it becomes the current cell. The behavior of the ENTER and ESC keys is unchanged in this case, but the cell remains in edit mode after the value is committed or reverted. You can also configure the control so that cells enter edit mode only when users type in the cell or only when users press F2. Finally, you can prevent cells from entering edit mode except when you call the BeginEdit method.

 

The following table describes the different edit modes available:

EditMode value

Description

EditOnEnter

Editing begins when the cell receives focus. This mode is useful when pressing the TAB key to enter values across a row, or when pressing the ENTER key to enter values down a column.

EditOnF2

Editing begins when F2 is pressed while the cell has focus. This mode places the selection point at the end of the cell contents.

EditOnKeystroke

Editing begins when any alphanumeric key is pressed while the cell has focus.

EditOnKeystrokeOrF2

Editing begins when any alphanumeric key or F2 is pressed while the cell has focus.

EditProgrammatically

Editing begins only when the BeginEdit method is called.

What is the DataGridView
Differences between the DataGridView and DataGrid controls
Highlight of features
Structure of DGV
Architecture Elements
Cells and Bands