private void btnDeleteSelected_Click(object sender, EventArgs e) { if (dgvUsers.SelectedRows.Count > 0) { DialogResult userConfirmation = MessageBox.Show("Are you sure to delete selected user?", "Confirm", MessageBoxButtons.YesNoCancel); if (userConfirmation != System.Windows.Forms.DialogResult.Yes) { return; } this.Cursor = Cursors.WaitCursor; try { string User_Name = Convert.ToString(dgvUsers.SelectedRows[0].Cells["User_Name"].Value); BusinessRules objBusinessRules = new BusinessRules(); using (DataTable dt = objBusinessRules.DeleteUser(User_Name)) { switch (Convert.ToInt16(dt.Rows[0][0])) { case -2: { MessageBox.Show("Selected user has already been deleted.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Stop); SearchUsers(string.Empty, txtSearchFirstName.Text.Trim(), txtSearchLastName.Text.Trim()); break; } case 0: { MessageBox.Show("User deleted successfully.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); SearchUsers(string.Empty, txtSearchFirstName.Text.Trim(), txtSearchLastName.Text.Trim()); break; } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { this.Cursor = DefaultCursor; } } }