473,703 Members | 3,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

combobox selectedindexch anged event

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 apparently
somehow the result of having changed the combobox.Items collection.

If, trying to fix this, I manually do this:

combobox1.Selec tedIndex = 0;

This reinvokes the SelectedIndexCh anged event and I am in an infinite
loop. The same thing happens if I change the text property of the
combobox instead of the selectedindex.

The behavior I am trying to accomplish is a drop down substitution list
for a basketball scoring program. The players in the game are listed in
combo boxes, and each combobox contains the set of players that could be
substituted for that player, so it dynamically changes whenever a
substitution is made.

Any ideas?

Terry Brown
Stickman Software
www.stickmansoftware.com
Dec 30 '06 #1
6 10815
I tried to fix this by setting the enabled property of the combobox to
false while modifying things, but that doesn't work either.

On Sat, 30 Dec
2006 16:47:11 +0000, tbrown wrote:
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 apparently
somehow the result of having changed the combobox.Items collection.

If, trying to fix this, I manually do this:

combobox1.Selec tedIndex = 0;

This reinvokes the SelectedIndexCh anged event and I am in an infinite
loop. The same thing happens if I change the text property of the
combobox instead of the selectedindex.

The behavior I am trying to accomplish is a drop down substitution list
for a basketball scoring program. The players in the game are listed in
combo boxes, and each combobox contains the set of players that could be
substituted for that player, so it dynamically changes whenever a
substitution is made.

Any ideas?

Terry Brown
Stickman Software
www.stickmansoftware.com
Dec 30 '06 #2
Do you mean the first one in the list is always the one "playing", and
when you substitute someone else for them, you want the other person
to show up as the first one in the list instead?

Robin S.
------------------------------------------

"tbrown" <tt****@yahoo.c omwrote in message
news:jKwlh.780$ NO5.752@trndny0 1...
>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
apparently
somehow the result of having changed the combobox.Items collection.

If, trying to fix this, I manually do this:

combobox1.Selec tedIndex = 0;

This reinvokes the SelectedIndexCh anged event and I am in an infinite
loop. The same thing happens if I change the text property of the
combobox instead of the selectedindex.

The behavior I am trying to accomplish is a drop down substitution
list
for a basketball scoring program. The players in the game are listed
in
combo boxes, and each combobox contains the set of players that could
be
substituted for that player, so it dynamically changes whenever a
substitution is made.

Any ideas?

Terry Brown
Stickman Software
www.stickmansoftware.com

Dec 30 '06 #3
The list I build contains the player currently playing as the first entry
(this is so that the user can cancel the substitution by tapping
anywhere). That player is followed by a list of all other players on the
roster who are not playing (so they could enter the game), and this
portion of the list is sorted alphabetically/numerically.

The problem that arises is that everytime a substitution is made the
SelectedIndexCh anged event is caused, and then, because a substitution was
made, the list changes (now the players not in the game are different),and
this change also causes a SelectedIndexCh anged event.

I'm beginning to believe that .Net simply doesn't have a control that does
what I want. I have programmed PalmOS, and I want a popup list. In the
PalmOS control, changing the list items or order doesn't create an event,
the only event that's created is a selection from the list. If the user
pops up the list and then taps outside the boundaries of the list, the
list is dismissed with no event.

I can't seem to find or build a control that does this in .Net. Maybe
it's all way too complicated for my meager brain :)

Terry Brown
www.stickmansoftware.com
On Sat, 30 Dec 2006 13:26:03 -0800, RobinS wrote:
Do you mean the first one in the list is always the one "playing", and
when you substitute someone else for them, you want the other person
to show up as the first one in the list instead?

Robin S.
------------------------------------------

"tbrown" <tt****@yahoo.c omwrote in message
news:jKwlh.780$ NO5.752@trndny0 1...
>>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
apparently
somehow the result of having changed the combobox.Items collection.

If, trying to fix this, I manually do this:

combobox1.Sele ctedIndex = 0;

This reinvokes the SelectedIndexCh anged event and I am in an infinite
loop. The same thing happens if I change the text property of the
combobox instead of the selectedindex.

The behavior I am trying to accomplish is a drop down substitution
list
for a basketball scoring program. The players in the game are listed
in
combo boxes, and each combobox contains the set of players that could
be
substituted for that player, so it dynamically changes whenever a
substitution is made.

Any ideas?

Terry Brown
Stickman Software
www.stickmansoftware.com
Dec 31 '06 #4
Yeah, I'm getting to that. I'm first trying to figure out if my logic
was
the same as yours. So the first guy is the one playing, and
if they pick someone else in the list, they are now the one playing,
and everyone else is available as a substitute, so the one playing
goes to the top of the list. Right?

So you have an event handler for the SelectIndexChan ged event
on the combobox, and when it fires, it reloads the combobox
(or changes the order or whatever). Right? And this is re-firing
the SelectIndexChan ged event, which is causing your problem.
Is that right?

What you can do is define a boolean in your form called something
like "Loading". When loading your combobox, set the boolean to
True. Set the SelectedIndex to 0. When you are done loading the
combobox, set the boolean to False.

In your SelectIndexChan ged event, before calling the Load routine,
check the boolean, and only call the load routine if the boolean
is False. This way, if the event is fired because of your load routine,
it will know not to fire it again because it's *you* mucking with the
SelectIndex and not the user.

Robin S.
------------------------------------

"tbrown" <tt****@yahoo.c omwrote in message
news:xpDlh.198$ Am5.50@trndny03 ...
The list I build contains the player currently playing as the first
entry
(this is so that the user can cancel the substitution by tapping
anywhere). That player is followed by a list of all other players on
the
roster who are not playing (so they could enter the game), and this
portion of the list is sorted alphabetically/numerically.

The problem that arises is that everytime a substitution is made the
SelectedIndexCh anged event is caused, and then, because a substitution
was
made, the list changes (now the players not in the game are
different),and
this change also causes a SelectedIndexCh anged event.

I'm beginning to believe that .Net simply doesn't have a control that
does
what I want. I have programmed PalmOS, and I want a popup list. In
the
PalmOS control, changing the list items or order doesn't create an
event,
the only event that's created is a selection from the list. If the
user
pops up the list and then taps outside the boundaries of the list, the
list is dismissed with no event.

I can't seem to find or build a control that does this in .Net. Maybe
it's all way too complicated for my meager brain :)

Terry Brown
www.stickmansoftware.com
On Sat, 30 Dec 2006 13:26:03 -0800, RobinS wrote:
>Do you mean the first one in the list is always the one "playing",
and
when you substitute someone else for them, you want the other person
to show up as the first one in the list instead?

Robin S.
------------------------------------------

"tbrown" <tt****@yahoo.c omwrote in message
news:jKwlh.780 $NO5.752@trndny 01...
>>>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
apparently
somehow the result of having changed the combobox.Items collection.

If, trying to fix this, I manually do this:

combobox1.Sel ectedIndex = 0;

This reinvokes the SelectedIndexCh anged event and I am in an
infinite
loop. The same thing happens if I change the text property of the
combobox instead of the selectedindex.

The behavior I am trying to accomplish is a drop down substitution
list
for a basketball scoring program. The players in the game are
listed
in
combo boxes, and each combobox contains the set of players that
could
be
substituted for that player, so it dynamically changes whenever a
substitutio n is made.

Any ideas?

Terry Brown
Stickman Software
www.stickmansoftware.com

Dec 31 '06 #5
RobinS schreef:
What you can do is define a boolean in your form called something
like "Loading". When loading your combobox, set the boolean to
True. Set the SelectedIndex to 0. When you are done loading the
combobox, set the boolean to False.
A similar solution:

When the loading starts, remove the eventhandler...
And when the loading is done, attach it again...
--
Tim Van Wassenhove <url:http://www.timvw.be/>
Dec 31 '06 #6
thanks for the suggestion, Robin. I'll try this with another combobox I
need to do. For now, I ripped out the combobox code and have implemented
the substitutions stuff with a dialog. I can dismiss the dialog with one
click by setting the DialogResult value. This works well, although I
don't consider it a good user interface choice.

I'll let you know how this works on the other piece of the design.

On Sat, 30 Dec 2006 16:57:15 -0800, RobinS wrote:
Yeah, I'm getting to that. I'm first trying to figure out if my logic
was
the same as yours. So the first guy is the one playing, and
if they pick someone else in the list, they are now the one playing,
and everyone else is available as a substitute, so the one playing
goes to the top of the list. Right?

So you have an event handler for the SelectIndexChan ged event
on the combobox, and when it fires, it reloads the combobox
(or changes the order or whatever). Right? And this is re-firing
the SelectIndexChan ged event, which is causing your problem.
Is that right?

What you can do is define a boolean in your form called something
like "Loading". When loading your combobox, set the boolean to
True. Set the SelectedIndex to 0. When you are done loading the
combobox, set the boolean to False.

In your SelectIndexChan ged event, before calling the Load routine,
check the boolean, and only call the load routine if the boolean
is False. This way, if the event is fired because of your load routine,
it will know not to fire it again because it's *you* mucking with the
SelectIndex and not the user.

Robin S.
------------------------------------

"tbrown" <tt****@yahoo.c omwrote in message
news:xpDlh.198$ Am5.50@trndny03 ...
>The list I build contains the player currently playing as the first
entry
(this is so that the user can cancel the substitution by tapping
anywhere). That player is followed by a list of all other players on
the
roster who are not playing (so they could enter the game), and this
portion of the list is sorted alphabetically/numerically.

The problem that arises is that everytime a substitution is made the
SelectedIndexC hanged event is caused, and then, because a substitution
was
made, the list changes (now the players not in the game are
different),a nd
this change also causes a SelectedIndexCh anged event.

I'm beginning to believe that .Net simply doesn't have a control that
does
what I want. I have programmed PalmOS, and I want a popup list. In
the
PalmOS control, changing the list items or order doesn't create an
event,
the only event that's created is a selection from the list. If the
user
pops up the list and then taps outside the boundaries of the list, the
list is dismissed with no event.

I can't seem to find or build a control that does this in .Net. Maybe
it's all way too complicated for my meager brain :)

Terry Brown
www.stickmansoftware.com
On Sat, 30 Dec 2006 13:26:03 -0800, RobinS wrote:
>>Do you mean the first one in the list is always the one "playing",
and
when you substitute someone else for them, you want the other person
to show up as the first one in the list instead?

Robin S.
------------------------------------------

"tbrown" <tt****@yahoo.c omwrote in message
news:jKwlh.78 0$NO5.752@trndn y01...
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
apparently
somehow the result of having changed the combobox.Items collection.

If, trying to fix this, I manually do this:

combobox1.Se lectedIndex = 0;

This reinvokes the SelectedIndexCh anged event and I am in an
infinite
loop. The same thing happens if I change the text property of the
combobox instead of the selectedindex.

The behavior I am trying to accomplish is a drop down substitution
list
for a basketball scoring program. The players in the game are
listed
in
combo boxes, and each combobox contains the set of players that
could
be
substitute d for that player, so it dynamically changes whenever a
substituti on is made.

Any ideas?

Terry Brown
Stickman Software
www.stickmansoftware.com
Dec 31 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1373
by: jcb1269 | last post by:
How do you select an item in a combobox. I've tried the Click events and that works only when I actually click the combobox. I want to select an item in the combbox not the combbox itself. Any ideas?? Thanks.. Jim
0
5791
by: George Hartas | last post by:
I am using Visual C# .NET 2003 to make a ComboBox accept both mouse and keyboard selection. For mouse selection code, I double-clicked ComboBox to get the default "comboBox1_SelectedIndexChanged" event. This code (see below) by itself works as expected with a mouse. But when using keyboard arrows to navigate the ComboBox drop- down, the SelectedIndexChanged event is triggered which is what I don't want using the keyboard. Instead, I want...
3
16231
by: ScottO | last post by:
I would like the user to have to select something in a System.Windows.Forms.ComboBox. private void MyForm_Load(object sender, System.EventArgs e) { ... comboBox.DataSource = data; comboBox.SelectedIndex = -1; ... }
7
23528
by: NCrum | last post by:
I want to set the Default value of a Combobox for any changeable record and have got this working but it is totaly unsatisfactory see the code below I loop through the items in the Combo looking for a match between cVal and the selectedValue then stop when I do have a match the obvious problem is that each iteration fires the selectedIndexChanged but also for a large list this will slow everything down. There must be a better way int...
5
2153
by: ross kerr | last post by:
Hi All, I am extending the combobox to create a control that selects an item based on the text the user is typing into the text area of the control. I have an issue that occurs only when i drop down the combo box as the users typing. When the on leave event is fired the value in the selected
7
8794
by: sparkle | last post by:
Hi Everybody, I'm filling a combobox from a class, which works fine on it's own. But when I insert code to fill in other controls something in the combobox fill is causing the SelectedIndexChanged event to happen when the form (hence combobox) loads, not when I select something from the combobox. Do I have something in the wrong order? I've read that that sometimes
2
3684
by: blue_nirvana | last post by:
I use a AddHandler statement in the load event of a form to assoicate a routine with a combobox. When I populate the form, I select the approiate value from the combobox by using combobox.selectedvalue = value. The weird thing is sometimes this causes the assoicated routine to be called and sometimes it does not. The combobox below it that is completely identical except for the name works every time. After the form is displayed, you can...
0
1756
by: peter78 | last post by:
I wanted to implement an autocomplete feature on the combobox where you would type in partial text and it would try to match it for you. It doesn't exist in .Net yet, but I'm guessing it will in the next version. Here are instructions how to do it: http://support.microsoft.com/default.aspx?scid=kb;en-us;320107 There is one bug, though.
2
2965
by: tshad | last post by:
In my VS 2003 Windows Forms page, when I initially fill my ComboBox (SystemList), it goes to the SelectedIndexChanged event which calls the Loademails() function. I then call it again in the Form1Load function. How do I get it not to call it in the SelectedIndexChanged from the Form1Load function? Normally, I want it to call it but not when I initally fill the ComboBox. *********************************************************...
0
8672
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9257
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9123
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8969
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6594
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5923
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3125
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2462
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.