private void findPartnersMenuItem_Click(object sender, EventArgs e) { searchTextBox.Clear(); clearSearchResults(); resultsTree = mainTree.FindTradePartners(selectedCountry); searchBoxLabel.Text = "Displaying all Trade Partners for " + selectedCountry.Name + ": " + resultsTree.Count(); countryList.DataSource = resultsTree.GetCountries(); countryList.DisplayMember = "name"; backButton.Enabled = true; }
public CountryTree FindTradePartners(Country searchTerm) { CountryTree tradePartners = new CountryTree(); foreach (string partner in searchTerm.MainTradePartners) { foreach (Country country in GetCountries()) { if (country.Name.Equals(partner)) { tradePartners.InsertItem(country); } else if (country.MainTradePartners.Contains(searchTerm.Name) && !tradePartners.Contains(country)) { tradePartners.InsertItem(country); } } } return(tradePartners); }