Passing values between comboboxes

g10p

New member
Joined
Oct 14, 2009
Messages
1
Programming Experience
Beginner
Hi!

I have two comboboxes and 2nd is depending on 1st selected value. I know how to get value from first one but don't know how to use it as query parameter in second one. I tend to do this with graphic designer if possible and i try to avoid hard coding. I created query but can't connect it with some variable.

And after that i have to populate listbox after that using the same principle. I guess. Thanks.
 
The concept you need to google for is "cascading comboboxes"

If you data bind both your combos then you should make an event handler for firstComboBindingSource.CurrentChanged (this detects the changing selection) and in there, call secondComboTableAdapter.FillByXXX(myDataSet.SecondComboTable, DirectCast(DirectCast(firstComboBindingSource.Current, DataRowView).Row, MyDataSet.FirstComboTableRow).XXX)

This will clear the table the second combo binds to and refill it using the parameter of (whatever is chosen as current item in the first combo)

You need to make your second combo table adapter have a parameter query, like:

SELECT * FROM Cities WHERE State = @state


First combo = the states,
Call citiesTableAdapter.FillByState(myDataSet.Cities, "AZ")
Where "AZ" is the value gotten from examining the current selected item
 

Latest posts

Back
Top