Пример #1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         int    selectedRowIndex = adminDataGridView.SelectedCells[0].RowIndex;
         int    id       = (int)adminDataGridView.Rows[selectedRowIndex].Cells[0].Value;
         string itemname = adminDataGridView.Rows[selectedRowIndex].Cells[1].Value.ToString();
         if (MessageBox.Show($"Are you sure you want to delete Admin: {itemname}?", "Confirm delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             AdminsModel deleteAdmin = new AdminsModel()
             {
                 Id = id
             };
             PrepAndPaintDB.DeleteAdmin(deleteAdmin);
             PopulateDataGrid();
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Nothing selected to delete!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }