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