A Combo box doesn't fire event

S

sea#

I'm trying to use a combo box on a windows form which will change its
display on event of changing combo selection. This is the method I
wrote:

Wrote this code:

private void SurveyChooserCombo_SelectedIndexChanged(object sender,
EventArgs e)
{
if (SurveyChooserCombo.Text.Equals("Survey1"))
SrNo = 1;
else if (SurveyChooserCombo.Text.Equals("Survey2"))
SrNo = 2;
else if (SurveyChooserCombo.Text.Equals("Survey3"))
SrNo = 3;
else
SrNo = 3;
GetResults (SrNo);
}

SrNo, is an int represents survey no. Each time I change the item in
combo, the value of SrNo supposed to be changed, & be passed to
GetResults method, which in turn will change display on the form.
When I run the application the form doesn't change the display as
expected.
Why is that so?

sea#
 
S

sea#

What does not happen, does this method get executed when the combo box
Yes, it does get executed . I just don't see the results of it on the
form. The value of SrNo is allaways left SrNo =1. Form is diplaying
data based on this value.
 
G

Guest

Stick a breakpoint inside your function and see what is happening, based on
this code:

if (SurveyChooserCombo.Text.Equals("Survey1"))
SrNo = 1;
else if (SurveyChooserCombo.Text.Equals("Survey2"))
SrNo = 2;
else if (SurveyChooserCombo.Text.Equals("Survey3"))
SrNo = 3;
else
SrNo = 3;

if SrNo ==1 at the end then your text must always be Survey1.

Instead of testing the text value, try to change that to use the
SelectedIndex property of the combo box to test your logic.

Mark.
 
S

sea#

I did try to work with debbugger. after looping over the method twice
with SurveyChooserCombo.Text = "Survey1", I got this:
message box:
"there is no source code available for current location".
It happans with the code Mark sent, with original mine & with this one,
too:

private void SurveyChooserCombo_SelectedIndexChanged(object sender,
EventArgs e)
{
if (SurveyChooserCombo.SelectedIndex==0)
SrNo = 1;
else if (SurveyChooserCombo.SelectedIndex==1)
SrNo = 2;
else if (SurveyChooserCombo.SelectedIndex==2)
SrNo = 3;
else
SrNo = 3;
GetResults (SrNo);
}
 
S

sea#

This is becoming bizar now.
After removing an extra click event I had, now when I run it with a
breakpoints on each if, I get the result I want. Once I remove
breakpoints, the magic is gone. No change in display!
What would you say about that?

sea#
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top