private void btnDelete_Click(object sender, EventArgs e) { if (dgvReader.SelectedCells.Count > 0) { int selectedrowindex = dgvReader.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = dgvReader.Rows[selectedrowindex]; string id = selectedRow.Cells["clmnReaderId"].Value.ToString(); DialogResult result = MessageBox.Show("Do you want to delete reader: " + selectedRow.Cells["clmnReaderName"].Value + "?", "Warning", MessageBoxButtons.OKCancel); switch (result) { case DialogResult.Cancel: break; case DialogResult.OK: ReaderBLL readerBLL = new ReaderBLL(selectedRow.Cells["clmnReaderName"].Value.ToString(), Convert.ToInt64(selectedRow.Cells["clmnReaderId"].Value.ToString()), selectedRow.Cells["clmnAddress"].Value.ToString(), selectedRow.Cells["clmnPhone"].Value.ToString(), selectedRow.Cells["clmnEmail"].Value.ToString(), Convert.ToDateTime(selectedRow.Cells["clmnDateallocated"].Value), Convert.ToDateTime(selectedRow.Cells["clmnDateend"].Value), Convert.ToDateTime(selectedRow.Cells["clmnDateallocated"].Value), Convert.ToBoolean(selectedRow.Cells["clmnStaff"].Value), Convert.ToInt32(selectedRow.Cells["clmnGraduation"].Value)); if (ReaderDAL.getReaderItem(readerBLL) == null) { MessageBox.Show("Can't delete! this Reader still not to give back of book"); break; } else { ReaderDAL.deleteReader(readerBLL); MessageBox.Show("Delete complete!", "Success"); this.LoadDataToDataGridView(); break; } } } }