By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 2,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

Skipping the SelectedIndexChanged event

P: n/a
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?
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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...)
-----Original Message-----
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 thereinstead of InitializeComponent?
.

Nov 15 '05 #2

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

GP

"bpschmid" <bp******@hotmail.com> wrote in message
news:08****************************@phx.gbl...
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...)
-----Original Message-----
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?
.

Nov 15 '05 #3

P: n/a
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.
-----Original Message-----
I moved the assignment to the Form_onLoad function but
that's not working either. The SelectedIndexChange event
still gets fired as soon as OnLoad finishes. All I'm
doing to load the combo box is fill a dataset (it's a
bound control), so what's causing the SelectedIndex to
change?
-----Original Message-----
Delete the event - declaration(this.DropDown1.SelectedIndexChanged += new
System.EventHandler...) from the InitalizeCompontent()

function, and add it
after the Loading of the DropDown

GP

"bpschmid" <bp******@hotmail.com> wrote in message
news:08****************************@phx.gbl...
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 foror
not...)

>-----Original Message-----
>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 aroundthis? >Is there another event that I can use to turn the flag
>off? Or assign my SelectedIndexChanged event handler
there
>instead of InitializeComponent?
>.
>

.

.

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.