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.
C#
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);
}
}
VB
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
No comments:
Post a Comment