Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have got 2 combo box one contain roll no. and second contain reg. no.

now when I select roll no. Im supposed to show student detail, with reg. no. in sec. combo box of that roll no. and visa-versa.


Problem is the moment it reach to cmbregno.Text = dr.GetValue(0).ToString())

it went to the cmbregno_SelectedIndexChanged method. and do process the method.

and when I search by regno. than it go the cmbRoll_SelectedIndexChanged and process that method.

How to stop other method to run when it came to that point of reading value.
Posted
Comments
CHill60 30-Jan-15 6:02am    
You will need to show us the code that you are using !
BillWoodruff 30-Jan-15 11:15am    
The only way you can have recursive interaction of two ComboBoxes is if both have their 'whatever_changed' EventHandlers wired together so they interact. So, show your code.

1 solution

Use a bool variabe stating if is your code who is changing the combo index,something like

C#
bool codeChanging=false;

cmbregno_SelectedIndexChanged(sender...)
{
    if (!codeChanging)
    {
       //do whatevere you are doing here now
       codeChanging=true;
       cmbrollno= dr.GetValue(0).ToString())
     }
     else
     {
        codeChanging=false;
     }

}

cmbrollno_SelectedIndexChanged(sender...)
{
    if (!codeChanging)
    {
       //do whatevere you are doing here now
       codeChanging=true;
       cmbregno= dr.GetValue(0).ToString())
     }
     else
     {
        codeChanging=false;
     }

}
 
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