I have 2 comboboxes in a form.
I’d like the selected value in combobox1 to change when the list in combobox2 gets updated.
For Example: ComboBox1 has names of mobile companies and ComboBox2 containing the list of all mobile phones of that company.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assume you have a dictionary that associates phone models to their manufacturers:
You can get the items to be displayed in the left combo box as:
You do this only once, for example in the form’s
Loadevent. Note: ThebrandsAndModelsdictionary must be an instance variable, not a local variable as we need to access it later on.Then, you’d have to assign an event handler for the
SelectedIndexChangedevent, in which you replace the items in the second combo box with the items in the array for the selected brand:If all of this came from a database, things would be much nicer using data bindings as described in the answers to the question I’ve linked in my comment to your question.