Skipping the SelectedIndexChanged event

S

sandman

I've got a combo box that has an event handler set for
SelectedIndexChanged event. The problem is that it's
firing at startup when I load data from the Form_OnLoad
event. I tried setting a flag at startup and turning it
off at the end of the OnLoad function but the
SelectedIndexChange event gets called after OnLoad
finishes, so my flag is off. How can I get around this?
Is there another event that I can use to turn the flag
off? Or assign my SelectedIndexChanged event handler there
instead of InitializeComponent?
 
B

bpschmid

Perhaps this is too simple of an answer, but is your
problem that you don't want the event to fire the first
time the form loads up? You can do that by checking for
ISPostBack:

void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
stuff you only want to do each time the form
is submitted;
...
}
else
{
Do the stuff you want to do when the page initially
loads...
...
)
}

You can also do the reverse... check for (!IsPostBack) if
you have code you only want to execute when the page
initially loads.

(again, I'm not sure if this is what you are asking for or
not...)
 
G

Günter Prossliner

Delete the event - declaration (this.DropDown1.SelectedIndexChanged += new
System.EventHandler...) from the InitalizeCompontent() function, and add it
after the Loading of the DropDown

GP
 
S

sandman

Never mind ... I found out what the problem is: there's a
bug in the tabcontrol (KnowledgeBase Article 820633) that
calls a bunch of ComboBox events including this one. So I
had to change the event handler code so it didn't cause
problems. Thanks for your help.
 

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