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

SelectedIndexChanged method always called

P: n/a
Hello,

I have combobox with a selectedindexchanged method that seems to be
called when starting the application, launching the form with the
combobox and making a change in the drop down box of the combobox. Can
anyone tell me why the method is called so often? I would only like
the method executed when a user makes a change in the drop down box.
Am I using the incorrect method. Thanks.

Jan 4 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Let's get some terminology straight so that we can understand you issue ...

You have a Form with a ComboBox control and that ComboBox has an event
handler attached to it's SelectedIndexChanged event.

You are observing that the SelectedIndexChanged event of the ComboBox is
being fired at points where you think it shouldn't be.

Those times are:

When the application starts

When the form containing the ComboBox is launched

When you change the item that is selected in the drop-down list portion of
ComboBox

Is that a fair interpretation of what you are experiencing? (Let's assume
that it is.)

The only way that the event could possibly fire when the application starts
is if the Form containing the ComboBox is loaded and/or shown at startup
(either as the startup form or by way of code you have added). This means
that two of the 'times' are actually a single 'time'.

It is apparent that the SelectedIndexChanged event handler is 'wired' at
design time by way of a 'Handles' clause on it's declaration.

It is also apparent that the list part of your ComboBox is 'bound' to some
datasource and the default behaviour, when 'bound' is that the first item in
the last part is automatically selected, thus causing the 'pre-wired'
SelectedIndexChanged event to fire.

To circumvent this behaviour, do not 'pre-wire' the eventhandler, but in the
Load event handler for the form, insert code something like the following:

MyComboBox.SelectedIndex = 0

AddHandler MyComboBox.SelectedIndexchanged, Addressof
MyComboBox_SelectedIndexChanged

Because the ComboBox is initialized before the Load event for the form is
fired, no SelectedIndexChanged events for the ComboBox will be fired until
after you have 'added' the 'handler'.

In Addition, be aware (be very aware) that when you change selections in the
ComboBox, the SelectedIndexChanged event will fire twice. The first time is
the current selection being 'deselected' and the second is the new selection
being 'selected' and you need to account for this in the event handler.
<la******@yahoo.comwrote in message
news:11**********************@s34g2000cwa.googlegr oups.com...
Hello,

I have combobox with a selectedindexchanged method that seems to be
called when starting the application, launching the form with the
combobox and making a change in the drop down box of the combobox. Can
anyone tell me why the method is called so often? I would only like
the method executed when a user makes a change in the drop down box.
Am I using the incorrect method. Thanks.

Jan 5 '07 #2

P: n/a
You said:
ComboBox, the SelectedIndexChanged event will fire twice
How? I get one and only one event when I make a selection.


"Stephany Young" <noone@localhostwrote in message
news:uE**************@TK2MSFTNGP04.phx.gbl...
Let's get some terminology straight so that we can understand you issue
...

You have a Form with a ComboBox control and that ComboBox has an event
handler attached to it's SelectedIndexChanged event.

You are observing that the SelectedIndexChanged event of the ComboBox is
being fired at points where you think it shouldn't be.

Those times are:

When the application starts

When the form containing the ComboBox is launched

When you change the item that is selected in the drop-down list portion
of ComboBox

Is that a fair interpretation of what you are experiencing? (Let's assume
that it is.)

The only way that the event could possibly fire when the application
starts is if the Form containing the ComboBox is loaded and/or shown at
startup (either as the startup form or by way of code you have added).
This means that two of the 'times' are actually a single 'time'.

It is apparent that the SelectedIndexChanged event handler is 'wired' at
design time by way of a 'Handles' clause on it's declaration.

It is also apparent that the list part of your ComboBox is 'bound' to some
datasource and the default behaviour, when 'bound' is that the first item
in the last part is automatically selected, thus causing the 'pre-wired'
SelectedIndexChanged event to fire.

To circumvent this behaviour, do not 'pre-wire' the eventhandler, but in
the Load event handler for the form, insert code something like the
following:

MyComboBox.SelectedIndex = 0

AddHandler MyComboBox.SelectedIndexchanged, Addressof
MyComboBox_SelectedIndexChanged

Because the ComboBox is initialized before the Load event for the form is
fired, no SelectedIndexChanged events for the ComboBox will be fired until
after you have 'added' the 'handler'.

In Addition, be aware (be very aware) that when you change selections in
the ComboBox, the SelectedIndexChanged event will fire twice. The first
time is the current selection being 'deselected' and the second is the new
selection being 'selected' and you need to account for this in the event
handler.
<la******@yahoo.comwrote in message
news:11**********************@s34g2000cwa.googlegr oups.com...
>Hello,

I have combobox with a selectedindexchanged method that seems to be
called when starting the application, launching the form with the
combobox and making a change in the drop down box of the combobox. Can
anyone tell me why the method is called so often? I would only like
the method executed when a user makes a change in the drop down box.
Am I using the incorrect method. Thanks.


Jan 6 '07 #3

P: n/a
Sorry. I was thinking of something else and had a rush of blood to the head.
"Mudhead" <no*****@yourhouse.comwrote in message
news:OK*************@TK2MSFTNGP02.phx.gbl...
You said:
>ComboBox, the SelectedIndexChanged event will fire twice

How? I get one and only one event when I make a selection.


"Stephany Young" <noone@localhostwrote in message
news:uE**************@TK2MSFTNGP04.phx.gbl...
>Let's get some terminology straight so that we can understand you issue
...

You have a Form with a ComboBox control and that ComboBox has an event
handler attached to it's SelectedIndexChanged event.

You are observing that the SelectedIndexChanged event of the ComboBox is
being fired at points where you think it shouldn't be.

Those times are:

When the application starts

When the form containing the ComboBox is launched

When you change the item that is selected in the drop-down list portion
of ComboBox

Is that a fair interpretation of what you are experiencing? (Let's assume
that it is.)

The only way that the event could possibly fire when the application
starts is if the Form containing the ComboBox is loaded and/or shown at
startup (either as the startup form or by way of code you have added).
This means that two of the 'times' are actually a single 'time'.

It is apparent that the SelectedIndexChanged event handler is 'wired' at
design time by way of a 'Handles' clause on it's declaration.

It is also apparent that the list part of your ComboBox is 'bound' to
some datasource and the default behaviour, when 'bound' is that the first
item in the last part is automatically selected, thus causing the
'pre-wired' SelectedIndexChanged event to fire.

To circumvent this behaviour, do not 'pre-wire' the eventhandler, but in
the Load event handler for the form, insert code something like the
following:

MyComboBox.SelectedIndex = 0

AddHandler MyComboBox.SelectedIndexchanged, Addressof
MyComboBox_SelectedIndexChanged

Because the ComboBox is initialized before the Load event for the form is
fired, no SelectedIndexChanged events for the ComboBox will be fired
until after you have 'added' the 'handler'.

In Addition, be aware (be very aware) that when you change selections in
the ComboBox, the SelectedIndexChanged event will fire twice. The first
time is the current selection being 'deselected' and the second is the
new selection being 'selected' and you need to account for this in the
event handler.
<la******@yahoo.comwrote in message
news:11**********************@s34g2000cwa.googleg roups.com...
>>Hello,

I have combobox with a selectedindexchanged method that seems to be
called when starting the application, launching the form with the
combobox and making a change in the drop down box of the combobox. Can
anyone tell me why the method is called so often? I would only like
the method executed when a user makes a change in the drop down box.
Am I using the incorrect method. Thanks.



Jan 6 '07 #4

P: n/a
Maybe you should listen to the album of the same name by Coldplay. ;-)

Robin S.
-----------------
"Stephany Young" <noone@localhostwrote in message
news:e3**************@TK2MSFTNGP02.phx.gbl...
Sorry. I was thinking of something else and had a rush of blood to the
head.
"Mudhead" <no*****@yourhouse.comwrote in message
news:OK*************@TK2MSFTNGP02.phx.gbl...
>You said:
>>ComboBox, the SelectedIndexChanged event will fire twice

How? I get one and only one event when I make a selection.


"Stephany Young" <noone@localhostwrote in message
news:uE**************@TK2MSFTNGP04.phx.gbl...
>>Let's get some terminology straight so that we can understand you
issue ...

You have a Form with a ComboBox control and that ComboBox has an
event handler attached to it's SelectedIndexChanged event.

You are observing that the SelectedIndexChanged event of the
ComboBox is being fired at points where you think it shouldn't be.

Those times are:

When the application starts

When the form containing the ComboBox is launched

When you change the item that is selected in the drop-down list
portion of ComboBox

Is that a fair interpretation of what you are experiencing? (Let's
assume that it is.)

The only way that the event could possibly fire when the application
starts is if the Form containing the ComboBox is loaded and/or shown
at startup (either as the startup form or by way of code you have
added). This means that two of the 'times' are actually a single
'time'.

It is apparent that the SelectedIndexChanged event handler is
'wired' at design time by way of a 'Handles' clause on it's
declaration.

It is also apparent that the list part of your ComboBox is 'bound'
to some datasource and the default behaviour, when 'bound' is that
the first item in the last part is automatically selected, thus
causing the 'pre-wired' SelectedIndexChanged event to fire.

To circumvent this behaviour, do not 'pre-wire' the eventhandler,
but in the Load event handler for the form, insert code something
like the following:

MyComboBox.SelectedIndex = 0

AddHandler MyComboBox.SelectedIndexchanged, Addressof
MyComboBox_SelectedIndexChanged

Because the ComboBox is initialized before the Load event for the
form is fired, no SelectedIndexChanged events for the ComboBox will
be fired until after you have 'added' the 'handler'.

In Addition, be aware (be very aware) that when you change
selections in the ComboBox, the SelectedIndexChanged event will fire
twice. The first time is the current selection being 'deselected'
and the second is the new selection being 'selected' and you need to
account for this in the event handler.
<la******@yahoo.comwrote in message
news:11**********************@s34g2000cwa.google groups.com...
Hello,

I have combobox with a selectedindexchanged method that seems to be
called when starting the application, launching the form with the
combobox and making a change in the drop down box of the combobox.
Can
anyone tell me why the method is called so often? I would only
like
the method executed when a user makes a change in the drop down
box.
Am I using the incorrect method. Thanks.



Jan 6 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.