diff --git a/dotnet-desktop-guide/framework/winforms/controls/default-keyboard-and-mouse-handling-in-the-windows-forms-datagridview-control.md b/dotnet-desktop-guide/framework/winforms/controls/default-keyboard-and-mouse-handling-in-the-windows-forms-datagridview-control.md index 338457b..aa4abd5 100644 --- a/dotnet-desktop-guide/framework/winforms/controls/default-keyboard-and-mouse-handling-in-the-windows-forms-datagridview-control.md +++ b/dotnet-desktop-guide/framework/winforms/controls/default-keyboard-and-mouse-handling-in-the-windows-forms-datagridview-control.md @@ -1,6 +1,7 @@ --- -title: Default keyboard and mouse handling in DataGridView control -ms.date: "02/13/2018" +title: Keyboard and mouse behavior in DataGridView control +description: Describes how the keyboard and mouse interacts with the DataGridView control in Windows Forms, including accessibility keyboard shortcuts. +ms.date: "02/08/2022" helpviewer_keywords: - "data grids [Windows Forms], mouse handling" - "DataGridView control [Windows Forms], navigation keys" @@ -11,7 +12,7 @@ helpviewer_keywords: - "navigation keys [Windows Forms], DataGridView control" ms.assetid: 4519b928-bfc8-4e8b-bb9c-b1e76a0ca552 --- -# Default keyboard and mouse handling in the Windows Forms DataGridView control +# Default keyboard and mouse behavior with the DataGridView control The following tables describe how users can interact with the control through a keyboard and a mouse. @@ -22,50 +23,51 @@ The following tables describe how users can interact with the 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 property value is `true`, moves the focus to the next control in the tab order of the parent container.| -|SHIFT+TAB|If the 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 property value is `true`, moves the focus to the previous control in the tab order of the parent container.| -|CTRL+TAB|If the property value is `false`, moves the focus to the next control in the tab order of the parent container.

If the 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 property value is `false`, moves the focus to the previous control in the tab order of the parent container.

If the 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.| -|CTRL+HOME|Moves the focus to the first cell in the control.| -|CTRL+END|Moves the focus to the last cell in the control.| -|CTRL+PAGE DOWN/UP|Same as PAGE DOWN or PAGE UP.| -|F2|Puts the current cell into cell edit mode if the property value is or .| -|F3|Sorts the current column if the property value is . 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 , puts the cell into edit mode and displays the drop-down list.| -|ALT+UP/DOWN ARROW|If the current cell is a , puts the cell into edit mode and displays the drop-down list.| -|SPACE|If the current cell is a , , or , raises the and events. If the current cell is a , also presses the button. If the current cell is a , also changes the check state.| -|ENTER|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 value into the current cell if the cell can be edited. By default, the display value for a cell value is the value of the property of the in effect for the current cell.| - +| 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 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 property value is `true`, moves the focus to the next control in the tab order of the parent container. | +| Shift + Tab | If the 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 property value is `true`, moves the focus to the previous control in the tab order of the parent container. | +| Ctrl + Tab | If the property value is `false`, moves the focus to the next control in the tab order of the parent container.

If the 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 property value is `false`, moves the focus to the previous control in the tab order of the parent container.

If the 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. | +| Ctrl + Home | Moves the focus to the first cell in the control. | +| Ctrl + End | Moves the focus to the last cell in the control. | +| Ctrl + Page down/up | Same as Page down or Page up. | +| F2 | Puts the current cell into cell edit mode if the property value is or . | +| F3 | Sorts the current column if the property value is . 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 , puts the cell into edit mode and displays the drop-down list. | +| Alt + Up/Down arrow | If the current cell is a , 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. | +| Space | If the current cell is a , , or , raises the and events. If the current cell is a , also presses the button. If the current cell is a , also changes the check state. | +| Enter | 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 value into the current cell if the cell can be edited. By default, the display value for a cell value is the value of the property of the in effect for the current cell. | + ### Selection keys - If the property is set to `false` and the property is set to , 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 the property is set to `false` and the property is set to , 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 the is set to or , the same behavior occurs but with the following additions. -|Key or key combination|Description| -|----------------------------|-----------------| -|SHIFT+SPACEBAR|Selects the full row or column (the same as clicking the row or column header).| -|navigation key (arrow key, PAGE UP/DOWN, HOME, END)|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).| +| Key or key combination | Description | +|-------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Shift + Spacebar | Selects the full row or column (the same as clicking the row or column header). | +| navigation key (arrow key, Page up/down, Home, End) | 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 is set to `false` and is set to or , 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 is set to `false` and is set to or , 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 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 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 is set to `true` and is set to or , the behavior of the anchor cell and current cell is the same, but only full rows or columns become selected or unselected. @@ -76,12 +78,12 @@ The following tables describe how users can interact with the [!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. -|Mouse action|Description| -|------------------|-----------------| -|Left mouse button down|Makes the clicked cell the current cell, and raises the event.| -|Left mouse button up|Raises the event| -|Left mouse button click|Raises the and events| -|Left mouse button down, and drag on a column header cell|If the property is `true`, moves the column so that it can be dropped into a new position.| +| Mouse action | Description | +|----------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Left mouse button down | Makes the clicked cell the current cell, and raises the event. | +| Left mouse button up | Raises the event | +| Left mouse button click | Raises the and events | +| Left mouse button down, and drag on a column header cell | If the property is `true`, moves the column so that it can be dropped into a new position. | ### Mouse selection @@ -89,24 +91,24 @@ The following tables describe how users can interact with the property is set to `false` and the property is set to , the following behavior occurs. -|Mouse action|Description| -|------------------|-----------------| -|Click left mouse button|Selects only the current cell if the user clicks a cell. No selection behavior if the user clicks a row or column header.| -|Click right mouse button|Displays a shortcut menu if one is available.| +| Mouse action | Description | +|--------------|---------------------------------------------------------------------------------------------------------------------------| +| Click | 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 is set to or , 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 is set to or , clicking any cell in a row or column will select the full row or column. - If is set to `true`, clicking a cell while pressing CTRL or SHIFT will modify a multi-cell selection. + If 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 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. + 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 is set to `true` and is set to or , 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. + If is set to `true` and is set to or , 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. - If is set to `true` and is set to or , clicking a cell while pressing SHIFT or CTRL behaves the same way except that only full rows and columns are affected. + If is set to `true` and is set to or , clicking a cell while pressing Shift or Ctrl behaves the same way except that only full rows and columns are affected. ## See also