Thursday, April 7, 2011

Get a list of countries without a database

A simple way to get a list of countries in .Net from the globaliZation namespace, without the need for storing them in a database.

Dim oci As New Dictionary(Of String, String)
For Each ci In CultureInfo.GetCultures(CultureTypes.SpecificCultures)
Dim ri = New RegionInfo(ci.Name)
If Not oci.ContainsKey(ri.EnglishName) Then
oci.Add(ri.EnglishName, ri.TwoLetterISORegionName)
End If
countries = oci.OrderBy(Function(p) p.Key)

IntRelocPassportNationalityCombo.DataSource = countries
IntRelocPassportNationalityCombo.BoundDisplay = "key"
IntRelocPassportNationalityCombo.BoundValue = "value"

Being that there are multiple cultures for the same country, i have only add unique values to the dictionary.

Cool huh?

No comments:

Post a Comment