Skip to main content

How to: Delete a Row When the CTRL+DEL Shortcut is Pressed

The following code deletes the focused row when the end-user presses the Ctrl+Del shortcut.

To process key press events, we handle the BaseView.KeyDown event. The row is deleted by calling the ColumnView.DeleteRow method.

private void gridView1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) {
    if (e.KeyCode == Keys.Delete && e.Modifiers == Keys.Control) {
        if (MessageBox.Show("Delete row?", "Confirmation", MessageBoxButtons.YesNo) != 
          DialogResult.Yes)
            return;
        GridView view = sender as GridView;                
        view.DeleteRow(view.FocusedRowHandle);
    }
}
See Also