private void удалитьToolStripMenuItem_Click(object sender, EventArgs e) { if (listView1.SelectedIndices.Count == 0) { return; } Country country = (Country)listView1.SelectedItems[0].Tag; if (country.Cities.Count > 0) { MessageBox.Show("Нельзя удалить страну, если у неё остались города!"); return; } foreach (var advertisement in advertisementDB.GetList()) { if (advertisement.Close != true && advertisement.Country == country) { MessageBox.Show("Существует незакрытое объявление с этой страной!"); return; } } if (MessageBox.Show("Точно удалить страну?", "Предупреждение!", MessageBoxButtons.YesNo) == DialogResult.Yes) { dB.Remove(country); } }
private void удалитьToolStripMenuItem_Click(object sender, EventArgs e) { if (listView1.SelectedIndices.Count == 0) { return; } Country country = (Country)listView1.SelectedItems[0].Tag; if (country.Cities.Count > 0) { MessageBox.Show("Нельзя удалить страну, если у неё остались города!"); return; } if (MessageBox.Show("Точно удалить страну?", "Предупреждение!", MessageBoxButtons.YesNo) == DialogResult.Yes) { dB.Remove(country); } }