473,548 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SelectedIndexCh anged method always called

Hello,

I have combobox with a selectedindexch anged 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
4 5240
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 SelectedIndexCh anged event.

You are observing that the SelectedIndexCh anged 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 SelectedIndexCh anged 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'
SelectedIndexCh anged 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.Sele ctedIndex = 0

AddHandler MyComboBox.Sele ctedIndexchange d, Addressof
MyComboBox_Sele ctedIndexChange d

Because the ComboBox is initialized before the Load event for the form is
fired, no SelectedIndexCh anged 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 SelectedIndexCh anged 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.goo glegroups.com.. .
Hello,

I have combobox with a selectedindexch anged 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
You said:
ComboBox, the SelectedIndexCh anged event will fire twice
How? I get one and only one event when I make a selection.


"Stephany Young" <noone@localhos twrote in message
news:uE******** ******@TK2MSFTN GP04.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 SelectedIndexCh anged event.

You are observing that the SelectedIndexCh anged 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 SelectedIndexCh anged 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'
SelectedIndexCh anged 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.Sele ctedIndex = 0

AddHandler MyComboBox.Sele ctedIndexchange d, Addressof
MyComboBox_Sele ctedIndexChange d

Because the ComboBox is initialized before the Load event for the form is
fired, no SelectedIndexCh anged 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 SelectedIndexCh anged 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.goo glegroups.com.. .
>Hello,

I have combobox with a selectedindexch anged 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
Sorry. I was thinking of something else and had a rush of blood to the head.
"Mudhead" <no*****@yourho use.comwrote in message
news:OK******** *****@TK2MSFTNG P02.phx.gbl...
You said:
>ComboBox, the SelectedIndexCh anged event will fire twice

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


"Stephany Young" <noone@localhos twrote in message
news:uE******** ******@TK2MSFTN GP04.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 SelectedIndexCh anged event.

You are observing that the SelectedIndexCh anged 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 SelectedIndexCh anged 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' SelectedIndexCh anged 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.Sele ctedIndex = 0

AddHandler MyComboBox.Sele ctedIndexchange d, Addressof
MyComboBox_Sel ectedIndexChang ed

Because the ComboBox is initialized before the Load event for the form is
fired, no SelectedIndexCh anged 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 SelectedIndexCh anged 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******@yaho o.comwrote in message
news:11******* *************** @s34g2000cwa.go oglegroups.com. ..
>>Hello,

I have combobox with a selectedindexch anged 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
Maybe you should listen to the album of the same name by Coldplay. ;-)

Robin S.
-----------------
"Stephany Young" <noone@localhos twrote in message
news:e3******** ******@TK2MSFTN GP02.phx.gbl...
Sorry. I was thinking of something else and had a rush of blood to the
head.
"Mudhead" <no*****@yourho use.comwrote in message
news:OK******** *****@TK2MSFTNG P02.phx.gbl...
>You said:
>>ComboBox, the SelectedIndexCh anged event will fire twice

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


"Stephany Young" <noone@localhos twrote in message
news:uE******* *******@TK2MSFT NGP04.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 SelectedIndexCh anged event.

You are observing that the SelectedIndexCh anged 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 SelectedIndexCh anged 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' SelectedIndexCh anged 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.Sele ctedIndex = 0

AddHandler MyComboBox.Sele ctedIndexchange d, Addressof
MyComboBox_Se lectedIndexChan ged

Because the ComboBox is initialized before the Load event for the
form is fired, no SelectedIndexCh anged 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 SelectedIndexCh anged 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******@yah oo.comwrote in message
news:11****** *************** *@s34g2000cwa.g ooglegroups.com ...
Hello,

I have combobox with a selectedindexch anged 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8359
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What I want to do is to allow the user to click on the row that corresponds to the correct address, and have the code behind populate the form's...
3
3729
by: Shawn | last post by:
I have a DataGrid with only one TemplateColumn wich contains a DropDownList. After I bind the DataGrid I fill the dropDownLists with values in ItemDataBound. None of the DropDownLists contains the same values. Some of these DropDownLists have AutoPostBack set to true, but I'm having trouble adding the SelectedIndexChanged event to them. This...
9
3803
by: j_stus | last post by:
Hello there I was trying to find something about this on web but with no success. I am using code behind. Basically I am creating drop down list dynamically. Everything works but calling SelectedIndexChanged event never fires up. I found some discussions regarding this problem, but couldn't find answer.... Here is my code. Protected...
2
3285
by: jnoody | last post by:
The problem I am having is with the SelectedIndexChanged event not always firing or the SelectedIndex property not being correct when the event does fire. The code is below, but here are some details first. The DropDownList is actually a custom control called DropDownListWithCommandEvent that inherits from DropDownList. The reason I have...
3
2824
by: martin1 | last post by:
Hi, All, I want user select first item (called All) in listbox, then all other items are selected by SetSelected method, but in loop (see code below) whenever going to SetSelected(), the SelectedIndexChanged event keep fire and loop doesn't go to next, finally the program stop at infinite loop. Sub lstCem_SelectedIndexChanged(ByVal...
11
36933
by: J055 | last post by:
Hi I have a dropdown control which is constructed in another dropdown control SelectedIndexChanged event protected void ddlParamType_SelectedIndexChanged(object sender, EventArgs e) { // some other code DropDownList ddlGroups = new DropDownList(); ddlGroups.SelectedIndexChanged += new
6
10786
by: tbrown | last post by:
I have a combobox with items like this: {one,two,three}. The selected index is 0, so "one" appears in the combobox text. When the user drops down the list, and selects "two", for example, I modify the Items collection to be {two,one,three} and now want "two" to appear in the combobox text. However, the combobox text is now blank. the is...
0
1183
by: Nathan Sokalski | last post by:
I have a page with an UpdatePanel that contains several TextBoxes and Buttons. There is also a ListBox outside of the UpdatePanel that is used as a trigger to populate these TextBoxes. The Buttons inside the UpdatePanel are used to update the values of the TextBoxes in a DB. However, when I use the Buttons to do the updating, they always use...
5
12899
by: GiJeet | last post by:
Hello, I'd like to force a call to the SelectedIndexChanged of a combo box from within a method. I tried to just call it like so: this.myComboBox.SelectedIndexChanged; but of course the event takes 2 parameters - object sender, EventArgs e and not sure how to pass these paras from my method. Should I just make up fake ones to pass? Any...
0
7512
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7438
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7707
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7951
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7803
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
751
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.