Partager via


Default Keyboard and Mouse Behavior in the DataGrid Control

Microsoft Silverlight will reach end of support after October 2021. Learn more.

This topic describes how users can interact with the DataGrid control by using the keyboard and mouse.

Default Keyboard Behavior

The following table lists the default keyboard behavior for the DataGrid.

NoteNote:

On a Macintosh computer, use the Command key instead of the CTRL key.

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, pressing the DOWN ARROW does nothing.

UP ARROW

Moves the focus to the cell directly above the current cell. If the focus is in the first row, pressing the UP ARROW 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, pressing the LEFT ARROW does nothing. If the focus is on a row group header, pressing the LEFT ARROW collapses the group.

RIGHT ARROW

Moves the focus to the next cell in the row. If the focus is in the last cell in the row, pressing the RIGHT ARROW does nothing. If the focus is on a row group header, pressing the RIGHT ARROW expands the group.

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 displayed. Moves the focus to the last displayed row without changing columns. If the last row is only partially displayed, scrolls the grid to fully display the last row.

PAGE UP

Scrolls the control upward by the number of rows that are displayed. Moves focus to the first displayed row without changing columns. If the first row is only partially displayed, scrolls the grid to fully display the first row.

TAB

If the current cell is in edit mode, moves the focus to the next cell in the current row. If the focus is already in the last cell of the row, commits any changes that were made and 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 current cell is not in edit mode, moves the focus to the next control in the tab order of the parent container.

SHIFT+TAB

If the current cell is in edit mode, moves the focus to the previous cell in the current row. If the focus is already in the first cell of the row, commits any changes that were made and 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 current cell is not in edit mode, moves the focus to the previous control in the tab order of the parent container.

CTRL+DOWN ARROW

Moves the focus to the last cell in the current column.

CTRL+UP ARROW

Moves the focus to the first cell in the current column.

CTRL+RIGHT ARROW

Moves the focus to the last cell in the current row.

CTRL+LEFT ARROW

Moves the focus to the first cell in the current row.

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

Same as PAGE DOWN.

CTRL+PAGE UP

Same as PAGE UP.

F2

If the DataGrid.IsReadOnly property is false and the DataGridColumn.IsReadOnly property is false for the current column, puts the current cell into cell edit mode.

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 and reverts any changes that were made in the control. If the underlying data source implements IEditableObject, pressing ESC a second time cancels edit mode for the entire row.

BACKSPACE

Deletes the character before the cursor when editing a cell.

DELETE

Deletes the character after the cursor when editing a cell.

CTRL+ENTER

Commits any changes to the current cell without moving the focus.

Selection Keys

If the SelectionMode property is set to Extended, the navigation behavior does not change, but navigating with the keyboard while pressing SHIFT (including CTRL+SHIFT) will modify a multi-row selection. Before navigation starts, the control marks the current row as an anchor row. When you navigate while pressing SHIFT, the selection includes all rows between the anchor row and the current row.

The following selection keys modify multi-row selection.

  • SHIFT+DOWN ARROW

  • SHIFT+UP ARROW

  • SHIFT+LEFT ARROW

  • SHIFT+RIGHT ARROW

  • SHIFT+HOME

  • SHIFT+END

  • SHIFT+PAGE DOWN

  • SHIFT+PAGE UP

  • CTRL+SHIFT+DOWN ARROW

  • CTRL+SHIFT+UP ARROW

  • CTRL+SHIFT+LEFT ARROW

  • CTRL+SHIFT+RIGHT ARROW

  • CTRL+SHIFT+HOME

  • CTRL+SHIFT+END

  • CTRL+SHIFT+PAGE DOWN

  • CTRL+SHIFT+PAGE UP

Default Mouse Behavior

The following table lists the default mouse behavior for the DataGrid.

NoteNote:

Clicking a cell with the left mouse button always changes the current cell. In Silverlight, clicking with the right mouse button always opens the Silverlight Configuration shortcut menu.

Mouse action

Description

Click an unselected row

Makes the clicked row the current row.

Click a cell in the current row

Puts the clicked cell into edit mode.

Drag a column header cell

If the DataGrid.CanUserReorderColumns property is true and the DataGridColumn.CanUserReorder property is true for the current column, moves the column so that it can be dropped into a new position.

Drag a column header separator

If the DataGrid.CanUserResizeColumns property is true and the DataGridColumn.CanUserResize property is true for the current column, resizes the column.

Click a column header cell

If the DataGrid.CanUserSortColumns property is true and the DataGridColumn.CanUserSort property is true for the current column, sorts the column.

Clicking the header of a column that is already sorted will reverse the sort direction of that column.

Pressing the SHIFT key while clicking multiple column headers will sort by multiple columns in the order clicked.

CTRL+click a row

If SelectionMode is set to Extended, modifies a non-contiguous multi-row selection.

If the row is already selected, deselects the row.

SHIFT+click a row

If SelectionMode is set to Extended, modifies a contiguous multi-row selection.

Click a row group header expander button

Expands or collapses the group.

Double-click a row group header

Expands or collapses the group.

Mouse Selection

If the SelectionMode property is set to Extended, clicking a row while pressing CTRL or SHIFT will modify a multi-row selection.

When you click a row while pressing CTRL, the row will change its selection state while all other rows retain their current selection state.

When you click a row while pressing SHIFT, the selection includes all rows between the current row and an anchor row located at the position of the current row before the first click. Subsequent clicks while pressing SHIFT changes the current row, but not the anchor row.

See Also

Reference