Click here to Skip to main content
15,071,635 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i have two combobox and a DB, I want that when i select an item from first comboBox, the second comboBox shows its subfields from DB. i write the code in the event of " Selected index change " from first comboBox ,but it doesnt work correctly.
how can i write its code?
please help me
[no name] 9-Apr-11 4:05am
Which combo box event you used??
can you provide code!!
Sandeep Mewara 9-Apr-11 6:49am
Elaborate: but it doesnt work correctly.

The first question is, have you wired the event. Something like:
comboBox1.SelectedIndexChanged +=
            new System.EventHandler(comboBox1_SelectedIndexChanged);

If that's done, the problem most likely is in the code you execute in the event. Since you didn't post the code, the best advice is to use the debugger to see what's going wrong.
Mika, yes, this is one possibility, my 5.
I know another one; please see my Answer.
Wendelius 10-Apr-11 1:14am
Thank you :)
Nish Nishant 10-Apr-11 0:28am
Voted 5, good response!
Wendelius 10-Apr-11 1:14am
Thanks :)
Please pat attention: this event is not fired when you simply change selection in the list part of the combo box. It is fired only when you confirm selection with Enter or Dbl-click, so the selection is shown in the edit box part of the combo. This is confusing, but this is how this event is fired.

Nish Nishant 10-Apr-11 0:28am
Voted 5, good alternative to Mika's reply.
Thank you, Nishant.
Wendelius 10-Apr-11 1:13am
This could also be the reason. My 5
Thank you, Mika.
Espen Harlinn 10-Apr-11 6:37am
My 5 :)
Sergey Alexandrovich Kryukov 10-Apr-11 20:30pm
Thank you, Espen.
Have a look on this[^].

Check whether first dropdown property AutoPostBack="True" or not.
Shahin Khorshidnia 9-Apr-11 7:36am
vote 5:
If she means your answer will help.
For first combobox...
public void cbo_1_Selected_Index_Changed(object sender, ...)
    //make the connection to the database sql querry select + where condition...
    //then the load the data into the second combo box

Make AutoPostBack="True" .It will done the trick. Nothing else is needed.

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