private void btnDelete_Click(object sender, EventArgs e) { try { id = gridList.SelectedRows[0].Cells[0].Value.ToString() == "" ? 0 : int.Parse(gridList.SelectedRows[0].Cells[0].Value.ToString()); if (id == 0) { MetroMessageBox.Show(this, "No record selected!", "Milk Collection", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } DialogResult result = MetroMessageBox.Show(this, "Are you sure you want to delete this record?", "Milk Collection", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { milkCollectionLogic.Delete(id); LoadMilkCollections(); MetroMessageBox.Show(this, "Record has been deleted!", "Milk Collection", MessageBoxButtons.OK, MessageBoxIcon.Information); id = 0; } } catch (Exception) { throw; } }