private void Button_Click_2(object sender, RoutedEventArgs e) { if (!(ListView.SelectedItem is Problem problem)) { return; } foreach (var t in _problems) { if (t.ProblemId != problem.ProblemId) { continue; } Connection.DeleteProblem(t.ProblemId); _problems.Remove(t); break; } }