Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Hi, Im new hear and could do with a bit of help. I have not managed to find this info anywhere and stumbled accross this community which seems to have some very helpful memebers!

I have an application with a comboBox populated with data from a database, I need the selection to then populate another comboBox with the appropriate data for example:

comboBox 1 has a number of food types i.e. Tinned, Fresh, Meat

if a user selected Tinned, comboBox 2 would be populated with all the tinned food contained within the database.

I hope i've explained that well enough! I appreciate any help immensly as I have been struggling with this for a few days now!

Thanks in advance,

Dan
Posted

1 solution

i can definitely help you with concept but except to me write complete code for you. Here is how you can do it

1. Load the data into first combobox on form load or any other event you like(say click of a button etc).

2.There is a even associated with combobox call "onSelectedIndexChange". On this even of combobox1 write the code which will pull the data based on selection made in combobox1. your query will look something like this

select column_name from tablename where index_comuln='"+combobox1.text+"'"


and then bound the result to combobox2.

P.S Do not copy paste this query. This will not work
 
Share this answer
 
Comments
DanHodgson88 23-May-11 8:09am    
thank you very much, that is exactly what I was looking for :) appreciate the reply!

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