private void DisplayDefenseStats(object sender, RoutedEventArgs e) { List <Team> teams = controller.TeamSort(1); List <object> stats = new List <object>(); bool foundSearch = false; if (searchBar.Text.Equals("")) { foundSearch = true; foreach (Team team in teams) { int interceptions = team.Interceptions; int sacks = team.Sacks; int points = team.Points; int tds = team.TD; if (interceptions != 0 || sacks != 0 || points != 0 || tds != 0) { stats.Add(new DefenseStats(team.Name, interceptions, sacks, points, tds)); } } } else { foreach (Team team in teams) { if (string.Equals(searchBar.Text, team.Name, StringComparison.OrdinalIgnoreCase)) { int interceptions = team.Interceptions; int sacks = team.Sacks; int points = team.Points; int tds = team.TD; stats.Add(new DefenseStats(team.Name, interceptions, sacks, points, tds)); foundSearch = true; break; } } } if (foundSearch) { DataContext = new DataGridTable(stats); } else { MessageBox.Show("Team not found", "Error"); } }