Search code examples
c#winformscomboboxregioninfo

Converting country names into thier own ThreeLetterISORegionName with RegionInfo (c# 2013 Winforms)


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


Solution

  • 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;
        }