Default keyboard and mouse behavior with the DataGridView control
Article
The following tables describe how users can interact with the DataGridView control through a keyboard and a mouse.
Note
To customize keyboard behavior, you can handle standard keyboard events such as KeyDown. In edit mode, however, the hosted editing control receives the keyboard input and the keyboard events do not occur for the DataGridView control. To handle editing control events, attach your handlers to the editing control in an EditingControlShowing event handler. Alternatively, you can customize keyboard behavior in a DataGridView subclass by overriding the ProcessDialogKey and ProcessDataGridViewKey methods.
Default keyboard handling
Basic navigation and entry keys
Key or key combination
Description
Down arrow
Moves the focus to the cell directly below the current cell. If the focus is in the last row, does nothing.
Left arrow
Moves the focus to the previous cell in the row. If the focus is in the first cell in the row, does nothing.
Right arrow
Moves the focus to the next cell in the row. If the focus is in the last cell in the row, does nothing.
Up arrow
Moves the focus to the cell directly above the current cell. If the focus is in the first row, does nothing.
Home
Moves the focus to the first cell in the current row.
End
Moves the focus to the last cell in the current row.
Page down
Scrolls the control downward by the number of rows that are fully displayed. Moves the focus to the last fully displayed row without changing columns.
Page up
Scrolls the control upward by the number of rows that are fully displayed. Moves focus to the first displayed row without changing columns.
Tab
If the StandardTab property value is false, moves the focus to the next cell in the current row. If the focus is already in the last cell of the row, moves the focus to the first cell in the next row. If the focus is in the last cell in the control, moves the focus to the next control in the tab order of the parent container.
If the StandardTab property value is true, moves the focus to the next control in the tab order of the parent container.
Shift + Tab
If the StandardTab property value is false, moves the focus to the previous cell in the current row. If the focus is already in the first cell of the row, moves the focus to the last cell in the previous row. If the focus is in the first cell in the control, moves the focus to the previous control in the tab order of the parent container.
If the StandardTab property value is true, moves the focus to the previous control in the tab order of the parent container.
Ctrl + Tab
If the StandardTab property value is false, moves the focus to the next control in the tab order of the parent container.
If the StandardTab property value is true, moves the focus to the next cell in the current row. If the focus is already in the last cell of the row, moves the focus to the first cell in the next row. If the focus is in the last cell in the control, moves the focus to the next control in the tab order of the parent container.
Ctrl + Shift + Tab
If the StandardTab property value is false, moves the focus to the previous control in the tab order of the parent container.
If the StandardTab property value is true, moves the focus to the previous cell in the current row. If the focus is already in the first cell of the row, moves the focus to the last cell in the previous row. If the focus is in the first cell in the control, moves the focus to the previous control in the tab order of the parent container.
Ctrl + arrow
Moves the focus to the farthest cell in the direction of the arrow.
Sorts the current column if the DataGridViewColumn.SortMode property value is Automatic. It's the same as clicking the current column header. Available since .NET Framework 4.7.2. To enable this feature, applications must target .NET Framework 4.7.2 or later versions or explicitly opt into accessibility improvements using AppContext switches.
F4
If the current cell is a DataGridViewComboBoxCell, puts the cell into edit mode and displays the drop-down list.
Alt + Up/Down arrow
If the current cell is a DataGridViewComboBoxCell, puts the cell into edit mode and displays the drop-down list.
Alt + Left/Right arrow
Increases or decreases the width of the current cell's column.
Commits any changes to the current cell and row and moves the focus to the cell directly below the current cell. If the focus is in the last row, commits any changes without moving the focus.
Esc
If the control is in edit mode, cancels the edit. If the control is not in edit mode, reverts any changes that have been made to the current row if the control is bound to a data source that supports editing or virtual mode has been implemented with row-level commit scope.
Backspace
Deletes the character before the insertion point when editing a cell.
Delete
Deletes the character after the insertion point when editing a cell.
Ctrl + Enter
Commits any changes to the current cell without moving the focus. Also commits any changes to the current row if the control is bound to a data source that supports editing or virtual mode has been implemented with row-level commit scope.
Ctrl + 0
Enters a DBNull.Value value into the current cell if the cell can be edited. By default, the display value for a DBNull cell value is the value of the NullValue property of the DataGridViewCellStyle in effect for the current cell.
Selection keys
If the MultiSelect property is set to false and the SelectionMode property is set to CellSelect, changing the current cell by using the navigation keys changes the selection to the new cell. The Shift, Ctrl, and Alt keys do not affect this behavior.
If a full row or column is selected, changing the current cell to a new row or column moves the selection to the full new row or column (depending on the selection mode).
If MultiSelect is set to false and SelectionMode is set to FullRowSelect or FullColumnSelect, changing the current cell to a new row or column by using the keyboard moves the selection to the full new row or column. The Shift, Ctrl, and Alt keys do not affect this behavior.
If MultiSelect is set to true, the navigation behavior does not change, but navigating with the keyboard while pressing Shift (including Ctrl + Shift) will modify a multi-cell selection. Before navigation begins, the control marks the current cell as an anchor cell. When you navigate while pressing Shift, the selection includes all cells between the anchor cell and the current cell. Other cells in the control will remain selected if they were already selected, but they may become unselected if the keyboard navigation temporarily puts them between the anchor cell and the current cell.
If MultiSelect is set to true and SelectionMode is set to FullRowSelect or FullColumnSelect, the behavior of the anchor cell and current cell is the same, but only full rows or columns become selected or unselected.
Default mouse handling
Basic mouse handling
Note
Clicking a cell with the left mouse button always changes the current cell. Clicking a cell with the right mouse button opens a shortcut menu, when one is available.
Selects only the current cell if the user clicks a cell. No selection behavior if the user clicks a row or column header.
Right-click
Displays a shortcut menu if one is available.
The same behavior occurs when the SelectionMode is set to RowHeaderSelect or ColumnHeaderSelect, except that, depending on the selection mode, clicking a row or column header will select the full row or column and set the current cell to the first cell in the row or column.
If MultiSelect is set to true, clicking a cell while pressing Ctrl or Shift will modify a multi-cell selection.
When you click a cell while pressing Ctrl, the cell will change its selection state while all other cells retain their current selection state.
When you click a cell or a series of cells while pressing Shift, the selection includes all cells between the current cell and an anchor cell located at the position of the current cell before the first click. When you click and drag the pointer across multiple cells, the anchor cell is the cell clicked at the beginning of the drag operation. Subsequent clicks while pressing Shift change the current cell, but not the anchor cell. Other cells in the control will remain selected if they were already selected, but they may become unselected if mouse navigation temporarily puts them between the anchor cell and the current cell.
If MultiSelect is set to true and SelectionMode is set to RowHeaderSelect or ColumnHeaderSelect, clicking a row or column header (depending on the selection mode) while pressing Shift will modify an existing selection of full rows or columns if such a selection exists. Otherwise, it will clear the selection and start a new selection of full rows or columns. Clicking a row or column header while pressing Ctrl, however, will add or remove the clicked row or column from the current selection without otherwise modifying the current selection.
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET Desktop feedback feedback
.NET Desktop feedback is an open source project. Select a link to provide feedback:
Learn to automate simulated mouse movement, clicks, typing, and key presses in Power Automate. Also, discover how to select and locate images or areas on the screen.