Results 1 to 3 of 3

Thread: binding all countries to a combobox?!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227

    binding all countries to a combobox?!

    hi, i have a registeration form , one of the fields in nationality so i need a list of all countries in alphabetical order , this is what i could think of

    Code:
    Dim cultures() As System.Globalization.CultureInfo = System.Globalization.CultureInfo.GetCultures(Globalization.CultureTypes.SpecificCultures)
            Dim countries As New System.Collections.ArrayList()
            Dim enm As IEnumerator = cultures.GetEnumerator
            While enm.MoveNext
                Dim str As String = CType(enm.Current, System.Globalization.CultureInfo).EnglishName
                Dim start As Int16 = str.IndexOf("(") + 1
                Dim finish As Int16 = str.IndexOf(")")
                countries.Add(str.Substring(start, finish - start))
            End While
            countries.Sort()
            nationality.DataSource = countries
    there must be an easier way

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    This ?
    VB Code:
    1. listBox1.Sorted=true

  3. #3
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Try using the SortListed Collection. Here is a quick snippet (it's in C#, but im sure you can decipher):

    Code:
    private void Page_Load(object sender, System.EventArgs e) {
    
        if (!Page.IsPostBack) {
            CultureInfo[] c = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
            SortedList countries = new SortedList();
    				
            foreach (CultureInfo o in c) {
                countries.Add(o.Name, o.EnglishName);
            }
    
            ddlCountries.DataTextField = "Value";
            ddlCountries.DataSource = countries;
            ddlCountries.DataBind();
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width