Click here to Skip to main content
15,887,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i'he 3 combobox for country,state and cities.when i select one country that coressponing states will display in 2nd combobox,and when i select one state that coressponing cities will display in 3rd combobox .give me the c# code .without database using windows application
Posted
Updated 29-Apr-12 1:38am
v2
Comments
Sandeep Mewara 29-Apr-12 10:14am    
give me the c# code .without database using windows application
No. No one will give you code.

Here is what is expected of enquirers:
1. TRY first what you want to do!
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.
Sandeep Mewara 29-Apr-12 10:14am    
Reason for my vote of 1
No effort.

The link given in solution 1 is good but it is for HTML with JavaScript.
For C# the following procedure can be used for Windows Forms
Create DataRelations between the Country, State and City DataTables using either the DataSet designer or programmatically.

Relation : CountryState
Parent Table: Country and primary key: CountryID
Child Table: State and Foreign key: CountryID
Relation : StateCity
Parent Table: State and primary key: StateID
Child Table: City and Foreign key: StateID
C#
//Create a BindingSource for Country ComboBox using Country table from DataSet1
BindingSource CountryBindingSource = New BindingSource(DataSet1, "Country");
//Now create a BindingSource with CountryBindingSource as the parent using the relation 
BindingSource StateBindingSource = New BindingSource(CountryBindingSource, "CountryState");
//Then create a BindingSource with StateBindingSource as the parent using the relation 
BindingSource CityBindingSource = New BindingSource(StateBindingSource, "StateCity");

//Set the DataSource, DisplayMember and ValueMember properties of the ComboBoxes as below
comboBox1.DataSource = CountryBindingSource;
comboBox1.DisplayMember = "Country";
comboBox1.ValueMember = "CountryID";
comboBox2.DataSource = StateBindingSource;
comboBox2.DisplayMember = "State";
comboBox2.ValueMember = "StateID";
comboBox3.DataSource = CityBindingSource;
comboBox3.DisplayMember = "City";
comboBox3.ValueMember = "CityID";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900