private void BtnAddArmy_Click(object sender, EventArgs e) { Army army = new Army() { ArmyName = txtAddArmy.Text }; ArmyDb.Add(army); MessageBox.Show($"{army.ArmyName} added"); UpdateComboBox(); }
private void btnDeleteArmy_Click(object sender, EventArgs e) { Army selectedArmy = ArmyDb.GetArmy((string)cbArmies.SelectedItem); using (ConfirmDialog dialog = new ConfirmDialog()) { dialog.ShowDialog(); if (dialog.DialogResult == DialogResult.Yes) { ArmyDb.Delete(selectedArmy); UpdateComboBox(); } } }
private void UpdateComboBox() { cbArmies.Items.Clear(); List <Army> allArmies = ArmyDb.GetAllArmies(); if (allArmies.Count > 0) { cbArmies.Enabled = true; for (int i = 0; i < allArmies.Count; i++) { cbArmies.Items.Add(allArmies[i].ArmyName); } } else { cbArmies.Enabled = false; } }