0

I’ve already written every country’s name in a ComboBox but now i want to get each country’s ThreeLetterISORegionName when i click the country’s name in the ComboBox and display it in a label, is that possible? Thanks

simon
  • 19
  • 4
  • You can use this class: [Get ISO country code from country name](https://stackoverflow.com/a/49313331/7444103). Adapt it as required, it's all already there. Maybe add a property if needed. – Jimi Aug 26 '19 at 18:23

1 Answers1

0

In your ComboBox's SelectedIndexChanged event, you could declare a new RegionInfo from the selected country, determine its ThreeLetterISORegionName, and set the label to it, like so:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        RegionInfo ri = new RegionInfo(comboBox1.Items[comboBox1.SelectedIndex].ToString());
        Label1.Text = ri.ThreeLetterISORegionName;
    }
Jayden933
  • 26
  • 5
  • This works but only if i have the Two letter code of the country, i wnat to get the country’s 3 letter when i click on the country’s full name, for example if i click on “United States” in my ComboBox, my label should display “USA”. – simon Aug 26 '19 at 18:57
  • Oh, I see. You may try declaring the RegionInfo using the country name like was done [here](https://stackoverflow.com/questions/14262021/get-regioninfo-by-country-name) – Jayden933 Aug 26 '19 at 19:10
  • Exactly, this will do it. Thanks for the help – simon Aug 26 '19 at 19:19