private void BtnDelete_Click(object sender, EventArgs e) { try { int selectedRowIndex = colourDataGridView.SelectedCells[0].RowIndex; int id = (int)colourDataGridView.Rows[selectedRowIndex].Cells[0].Value; string itemname = colourDataGridView.Rows[selectedRowIndex].Cells[1].Value.ToString(); if (MessageBox.Show($"Are you sure you want to delete Item: {itemname}?", "Confirm delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { JobColoursModel deleteId = new JobColoursModel() { Id = id }; PrepAndPaintDB.DeleteColour(deleteId); PopulateDataGrid(); } } catch (Exception) { MessageBox.Show("Nothing selected to delete!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } }