Delete Key Trapping?
-
Hello I have a data grid view and when I press the delete key, even though I have a message box to confirm the delete, the delete happens either way. Any ideas on trapping the delete key? thanks j private void dataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { DialogResult yn = MessageBox.Show("Are you sure you want to delete this row?", "DataGridView Delete", MessageBoxButtons.YesNo); if (yn == DialogResult.Yes) { } if (yn == DialogResult.No) { MessageBox.Show("record was not deleted"); } }
-
Hello I have a data grid view and when I press the delete key, even though I have a message box to confirm the delete, the delete happens either way. Any ideas on trapping the delete key? thanks j private void dataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { DialogResult yn = MessageBox.Show("Are you sure you want to delete this row?", "DataGridView Delete", MessageBoxButtons.YesNo); if (yn == DialogResult.Yes) { } if (yn == DialogResult.No) { MessageBox.Show("record was not deleted"); } }
Just use the KeyDown event for your datatgrid. The keydown event gets fired before the control knows about a key being pressed. Then you can check if the key pressed was the delete key, and then if you want to cancel the delete, set e.Handled to true.
My current favourite word is: PIE! Good ol' pie, it's been a while.
-
Just use the KeyDown event for your datatgrid. The keydown event gets fired before the control knows about a key being pressed. Then you can check if the key pressed was the delete key, and then if you want to cancel the delete, set e.Handled to true.
My current favourite word is: PIE! Good ol' pie, it's been a while.