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;
 }
        private void exportMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveCountries = new SaveFileDialog();

            saveCountries.Filter = "Save Countries to CSV file|*.csv";
            if (saveCountries.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string       headers = "Country,GDP growth,Inflation,Trade Balance,HDI Ranking,Main Trade Partners";
                string       format  = "{0},{1},{2},{3},{4},{5}";
                StreamWriter file;
                try
                {
                    file = new StreamWriter(saveCountries.FileName);
                    file.WriteLine(headers);
                    foreach (Country country in mainTree.GetCountries())
                    {
                        string partners = "[";
                        foreach (string partner in country.MainTradePartners)
                        {
                            partners = partners + partner.Replace(' ', '_') + ";";
                        }
                        partners = partners.Remove(partners.Length - 1);
                        partners = partners + "]";
                        file.WriteLine(String.Format(format, country.Name.Replace(' ', '_'), country.GdpGrowth, country.Inflation, country.TradeBalance, country.HdiRanking, partners));
                    }
                    if (file != null)
                    {
                        file.Close();
                    }
                }
                catch
                {
                    MessageBox.Show("Export was unsuccessful", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }