I wonder if there is already a build procedure in C# for making a combobox or list box that has names of all countries and when a country is selected another combobox is filled with the cities of that country??
Or someone can suggest me what to do!!
I wonder if there is already a build procedure in C# for making a combobox or list box that has names of all countries and when a country is selected another combobox is filled with the cities of that country??
Or someone can suggest me what to do!!
There is no such procedure. I suggest that you make a combo box and populate it with countries, and another one with cities when a country was selected. That way, you have full control over what countries and cities appear in your combo boxes.
Sure there is a procedure. You could start with a simple data structure:
public class Country
{
public string Name { get; set; }
public IList<City> Cities { get; set; }
public Country()
{
Cities = new List<City>();
}
}
public class City { public string Name { get; set; } }
Then, instantiate this structure, e.g. into a property of your form...
Countries =
new List<Country>
{
new Country
{
Name = "Germany",
Cities =
{
new City {Name = "Berlin"},
new City {Name = "Hamburg"}
}
},
new Country
{
Name = "England",
Cities =
{
new City {Name = "London"},
new City {Name = "Birmingham"}
}
}
};
In your form, instantiate two Binding Sources (BS):
Now you need two dropdowns:
and you should be pretty much done.