Hi!
I saw last time a windows application with two comboboxes (combobox1 with a list of countries and combobox2 with cities). Then when you click for example on the combobox1 and choose India. Its show on combobox2 all Indian's cities.
Anyone have an idea on it. But its coming from a sql datable, two tables I mean countries and cities
Thanx,
Mfwamba
Hemant SrivastavaPosted Jul 28, 2014, 2:52 PM
You could do something like in the Form_Load() method, populate all the countries from
the database into a comboBox1 and on any country selection in comboBox1, get all the cities from the database for that selected country and populate them into another comboBox2.
private void Form1_Load(object sender, EventArgs e)
{
//Get Countries from the database and load them into ComboBox1.
//comboBox1.DataSource = MyCountryDataTable;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedItem.ToString() != string.Empty)
{
//Fistly clear the old contents of the another ComboBox
comboBox2.DataSource = null;
//Get cities Data from the database for the selected country
// and load all the cities into another ComboBox2 in the following way
//comboBox2.DataSource = MyCityDataTable;
}
}