Wednesday, 14 March 2012

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.

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;

No comments:

Post a Comment