Click here to Skip to main content
15,886,815 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear All,
I've two combo boxes in windows form, One is for Province and the second one is for district. All i need is when someone selects an item (Province)all relevant Items (Districts) should come in second combobox, I've done it using table in DBMS but i want to do it directly with c#, any idea? Please help me!
Posted
Comments
Sergey Alexandrovich Kryukov 26-Mar-12 2:00am    
You did not tag your application type or UI library used. Tag it. WPF? Forms? Silverlight? ASP.NET? What?
--SA

As you have given us no clue what your UI is this may help.

On the selecteditemchange event of the first combo
Get the selected object and the foreign key needed to filter the second combo
Filter the data collection of the second combo using the FK details from the first combo.
 
Share this answer
 
There is 2 ways to do this. The first way is to have a complete list of all provinces and another list with all districts. The when your user selects a province, you can use LinQ on the List<district>, something like :-
C#
var selectedDistricts = from district in Districts where district.ProvinceID == selectedProvince.ID select district;


The other option is to have a function which looks up in the database and returns all districts with the selected provinces id.i.e
C#
"SELECT id, name, provinceID, etc FROM Districts WHERE provinceID = @provinceID;" 
where provinceid is the selected provinces id.
 
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