Skip to main content

GridControl.ProcessGridKey Event

Enables you to process key presses before they are processed by the grid control’s focused View and the active in-place editor.

Namespace: DevExpress.XtraGrid

Assembly: DevExpress.XtraGrid.v23.2.dll

NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

[DXCategory("Grid")]
public event KeyEventHandler ProcessGridKey

Event Data

The ProcessGridKey event's data class is KeyEventArgs. The following properties provide information specific to this event:

Property Description
Alt Gets a value indicating whether the ALT key was pressed.
Control Gets a value indicating whether the CTRL key was pressed.
Handled Gets or sets a value indicating whether the event was handled.
KeyCode Gets the keyboard code for a KeyDown or KeyUp event.
KeyData Gets the key data for a KeyDown or KeyUp event.
KeyValue Gets the keyboard value for a KeyDown or KeyUp event.
Modifiers Gets the modifier flags for a KeyDown or KeyUp event. The flags indicate which combination of CTRL, SHIFT, and ALT keys was pressed.
Shift Gets a value indicating whether the SHIFT key was pressed.
SuppressKeyPress Gets or sets a value indicating whether the key event should be passed on to the underlying control.

Remarks

To process key presses within a View, use the events provided by View objects (BaseView.KeyPress, BaseView.KeyDown and BaseView.KeyUp). Note that these events do not fire when a cell’s in-place editor is active.

To handle key presses within in-place editors, use dedicated events provided by in-place editors (RepositoryItem.KeyPress, RepositoryItem.KeyDown and RepositoryItem.KeyUp) or by the GridControl (EditorContainer.EditorKeyPress, EditorContainer.EditorKeyDown and EditorContainer.EditorKeyUp).

The ProcessGridKey event is designed for advanced cases that are not covered by these events.

The ProcessGridKey event is raised when the user presses a key but before this key press is processed by the grid control. After your ProcessGridKey event handler is complete, the current key press will, by default, be sent to the focused View or to the active in-place editor. To prevent this, set the Handled parameter to true.

Example

The following example shows how to use the GridControl.ProcessGridKey event to delete the selected record(s) in the currently focused View when the CTRL+DELETE shortcut is pressed.

private void gridControl1_ProcessGridKey(object sender, KeyEventArgs e) {
    ColumnView view = (sender as GridControl).FocusedView as ColumnView;
    if (view == null) return;
    if (e.KeyCode == Keys.Delete && e.Control && view.Editable && view.SelectedRowsCount > 0) {
        if (view.ActiveEditor != null) return; //Prevent record deletion when an in-place editor is invoked
        e.Handled = true;
        if (DevExpress.XtraEditors.XtraMessageBox.Show("Record deletion", "Delete?", MessageBoxButtons.YesNo) == DialogResult.Yes)
            view.DeleteSelectedRows();
    }
}
See Also