private void dgvHallBooking_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { try { if (e.Row.Cells[10].Value != null && mode == 1) { if (dgvHallBooking.Rows.Count == 2) { e.Cancel = true; btnDelete_Click(sender, e); } else { DialogResult result = MessageBox.Show("Are you sure you want to delete this record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { bool result2 = dbLayer.DeleteHallBooking(Convert.ToInt32(e.Row.Cells[10].Value.ToString())); if (result2) { MessageBox.Show("Successfully deleted!"); //dgvHallBooking.Rows.Add(1); } } else { e.Cancel = true; } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }