• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1209
  • Last Modified:

Change dropdownlist to combobox for windows forms.

I need the function on this page
http://www.sourcesnippets.com/csharp-country-dropdown-list-control.html

in C# code for windows forms.  any ideas?
0
casit
Asked:
casit
1 Solution
 
aherpsCommented:
For the most part - that is fine.

I've created a form with nothing but a combobox.  See code below
using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.ComponentModel;
using Microsoft.Win32;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
 
namespace Testing
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private List<string> GetCountries()
        {
            List<string> returnValues = new List<string>();
 
            RegistryKey countries =
             Registry.LocalMachine.OpenSubKey(
              "Software\\Microsoft\\Windows\\CurrentVersion" +
              "\\Telephony\\Country List");
 
            if (countries != null)
            {
                // Get the list of subkeys,
                // which is actually the country code
                string[] subkeys = countries.GetSubKeyNames();
 
                foreach (string ccode in subkeys)
                {
                    // Open the subkey, to get the country name
                    RegistryKey country = countries.OpenSubKey(ccode);
 
                    // ..get the country name from country key
                    returnValues.Add(country.GetValue("Name").ToString());
 
                    // We're done using the key, we should close it
                    country.Close();
                }
 
                // It's now safe to close the country list key
                countries.Close();
            }
 
            returnValues.Sort();
            return returnValues;
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            List<string> countries = GetCountries();
            foreach (string country in countries)
                comboBox1.Items.Add(country);
        }
    }
     
}

Open in new window

0
 
casitAuthor Commented:
Thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now