Display a confirmation box before deleting a row in the DataGridView
If the user clicks cancel, set e.cancel = true which cancels the row deletion.
C#
private void dgv_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{
if (!e.Row.IsNewRow)
{
DialogResult res = MessageBox.Show("Are you sure you want to delete this row?", "Delete confirmation",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (res == DialogResult.No)
e.Cancel = true;
}
}
Comments
Post a Comment