private void buttonDelete_Click(object sender, EventArgs e) { try { if (listViewDemand.SelectedItems.Count == 1) { Demand demand = listViewDemand.SelectedItems[0].Tag as Demand; Program.sAM.Demand.Remove(demand); Program.sAM.SaveChanges(); } textBoxAddress.Text = ""; textBoxMinPrice.Text = ""; textBoxMaxPrice.Text = ""; textBoxCatalog.Text = ""; } catch { MessageBox.Show("невозможно удалить, эта запись используется!", "ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }