private void buttonDel_Click(object sender, RoutedEventArgs e) { if (dataGridVisits.SelectedCells.Count != 0) { var result = MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { var cellInfo = dataGridVisits.SelectedCells[0]; VisitViewModel content = (VisitViewModel)(cellInfo.Item); int id = Convert.ToInt32(content.Id); try { logic.Delete(new VisitBindingModel { Id = id }); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } LoadData(); } } }
private void ButtonDel_Click(object sender, EventArgs e) { if (dataGridViewVisits.SelectedRows.Count == 1) { if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = Convert.ToInt32(dataGridViewVisits.SelectedRows[0].Cells[0].Value); try { visitLogic.Delete(new VisitBindingModel { Id = id }); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadData(); } } ClearForms(); }