Help !! listing country names in listbox

AbdallaHajjaj

New member
Joined
Nov 7, 2005
Messages
2
Programming Experience
Beginner
i was trying to write a code where i can use

system.globalization namespace
system.collections namespace

to fill a list box with the country names that .net offer in regioninfo class ..

i don't know how to print them all .. well i tried and here is my code

Dim countries1 As New RegionInfo("AE")
Dim countries2 As New RegionInfo("ZW")
Dim allcountries As Single
For allcountries = countries1.DisplayName To countries2.DisplayName
Me.ListBox1.Items.Add(allcountries)
Next

and i tried to use cultures .. but no country names ..

' Create a CultureInfo Variable
Dim cu As CultureInfo
' Loop through the CultureTypes Enumeration
' and list the Culture Name in the Listbox
For Each cu In CultureInfo.GetCultures(CultureTypes.AllCultures)
Me.ListBox1.Items.Add(cu.EnglishName)
Next

can any one please help me listing the 110 countries in system.globalization.regioninfo into a listbox :D
 
VB.NET:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Get only specific cultures, i.e. those that refer to a country.
        Dim cultures As Globalization.CultureInfo() = Globalization.CultureInfo.GetCultures(Globalization.CultureTypes.SpecificCultures)

        Dim countryCollection As New Specialized.StringCollection
        Dim country As String

        'Get all unique country names.
        For Each culture As Globalization.CultureInfo In cultures
            country = New Globalization.RegionInfo(culture.LCID).EnglishName

            If Not countryCollection.Contains(country) Then
                countryCollection.Add(country)
            End If
        Next

        Dim countries(countryCollection.Count - 1) As String

        'Add countries to the ListBox
        countryCollection.CopyTo(countries, 0)
        Me.ListBox1.Items.AddRange(countries)
    End Sub
You would presumably want to set the Sorted property of the ListBox to True so that the countries were listed alphabetically.
 
man .. ur amaaaaaaaaaaaaaaaaaaaaaaaazing .. although the code is big, but your code explains it all .. it is very readabul ..

thank you very much :)
 
Back
Top