private void btnDel_Click(object sender, RoutedEventArgs e) { int current = list.SelectedIndex; if (current != -1) { AIRule rule = new AIRule(); foreach (AIRule r in mRules.Rules) { if (r.ID == text.Text) { rule = r; } } Commands.DelRule command = new Commands.DelRule(mRules, rule); mCommandManager.Execute(command); if (current != list.Items.Count) { list.SelectedIndex = current; } else { list.SelectedIndex = current - 1; } } else { MessageBox.Show("Выберите элемент"); } }
private void btnDel_Click(object sender, RoutedEventArgs e) { int current = list.SelectedIndex; if (current != -1) { AIRule rule = new AIRule(); foreach (AIRule r in mRules.Rules) { if (r.ID == text.Text) rule = r; } Commands.DelRule command = new Commands.DelRule(mRules, rule); mCommandManager.Execute(command); if (current != list.Items.Count) list.SelectedIndex = current; else list.SelectedIndex = current - 1; } else MessageBox.Show("Выберите элемент"); }