Click here to Skip to main content
15,891,951 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
Posted
Comments
[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:
C#
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.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-Apr-11 22:42pm    
Mika, yes, this is one possibility, my 5.
I know another one; please see my Answer.
--SA
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.

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

Check whether first dropdown property AutoPostBack="True" or not.
 
Share this answer
 
Comments
Shahin Khorshidnia 9-Apr-11 7:36am    
vote 5:
but:
If she means asp.net 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


}
 
Share this answer
 
Make AutoPostBack="True" .It will done the trick. Nothing else is needed.
 
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