当最终用户按下 Ctrl+Del 快捷键时,下列代码删除获得焦点的行。 为了处理击键事件,接管了 BaseView.KeyDown 事件。 通过调用 ColumnView.DeleteRow 方法来删除行。

C#CopyCode image复制代码
    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);
        }
    }

Visual BasicCopyCode image复制代码
    Private Sub GridView1_KeyDown(ByVal sender As Object, _
      ByVal e As System.Windows.Forms.KeyEventArgs) Handles GridView1.KeyDown
        If (e.KeyCode = Keys.Delete And e.Modifiers = Keys.Control) Then
            If (MessageBox.Show("Delete row?", "Confirmation", _
              MessageBoxButtons.YesNo) <> DialogResult.Yes) Then Return
            Dim view As GridView = CType(sender, GridView)
            view.DeleteRow(view.FocusedRowHandle)
        End If
    End Sub