private void RmvBtn_Click(object sender, EventArgs e) { try { if (dataGridView1.SelectedRows.Count != 0) { DialogResult result = MessageBox.Show("Do You Want to Delete?", "Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (result.Equals(DialogResult.OK)) { DataGridViewRow row = this.dataGridView1.SelectedRows[0]; string id = row.Cells["id"].Value.ToString(); StoreDao store = new StoreDao(); store.delete(id); showlist(); MessageBox.Show("Deleted"); } } else { MessageBox.Show("Select the row you want to delete"); Store_Load(sender, e); } } catch (SqlException error) { if (error.Message.ToString() != "") { MessageBox.Show("Shop cannot be removed without clearing the inventory"); } } dataGridView1.ClearSelection(); }