private void searchCountryTextBox_TextChanged(object sender, EventArgs e) { AVLCountry searchTree = new AVLCountry(); string userInput = searchCountryTextBox.Text; var source = new AutoCompleteStringCollection(); if (userInput == "") { //refresh comboBox countryComboBox.DataSource = CountryAVLTree.GetAllCountries(); countryComboBox.DisplayMember = "countryName"; selectCountryLabel.Text = "Select Country: " + CountryAVLTree.Count().ToString(); //clear search results foreach (Country search in searchTree.GetAllCountries()) { searchTree.RemoveItem(search); } } else { //clear all user innput int countryCount = 0; currentCountry = null; countryComboBox.Text = ""; selectCountryLabel.Text = "Select Country: 0"; foreach (Country c in CountryAVLTree.GetAllCountries()) { if (c.CountryName.ToLower().StartsWith(userInput.ToLower().Trim())) { source.Add(c.CountryName); countryCount++; searchTree.InsertItem(c); } } foreach (Country search in searchTree.GetAllCountries()) { if (!search.CountryName.ToLower().StartsWith(userInput.ToLower().Trim())) { source.Remove(search.CountryName); countryCount--; searchTree.RemoveItem(search); } } countryComboBox.DataSource = searchTree.GetAllCountries(); countryComboBox.DisplayMember = "countryName"; selectCountryLabel.Text = "Select Country: " + countryCount; searchCountryTextBox.AutoCompleteCustomSource = source; } }
public AVLCountry fetchAllTradePartners(Country country) { AVLCountry tradePartners = new AVLCountry(); foreach (string partnerName in country.TradePartners) { foreach (Country c in GetAllCountries()) { if (c.CountryName == partnerName) { tradePartners.InsertItem(c); } } } return(tradePartners); }
private void tradePartners_Load(object sender, EventArgs e) { tradePartnersLabel.Text = "Showing Trade Partners of: " + current.CountryName.ToString(); dataTable = new DataTable(); dataTable.Columns.Add("Country"); dataTable.Columns.Add("GDP Growth"); dataTable.Columns.Add("Inflation"); dataTable.Columns.Add("Trade Balance"); dataTable.Columns.Add("HDI Ranking"); countryDataGridView.DataSource = dataTable; tradePartnersTree = refToMainTree.fetchAllTradePartners(current); dataTable.Clear(); foreach (Country c in tradePartnersTree.GetAllCountries()) { if (tradePartnersTree != null) { dataTable.Rows.Add(c.CountryName, c.GDPGrowth, c.Inflation, c.TradeBalance, c.HDIRanking); } } countryDataGridView.Update(); }