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

combobox selectedindexchanged event

P: n/a
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.SelectedIndex = 0;

This reinvokes the SelectedIndexChanged 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
Share this Question
Share on Google+
6 Replies


P: n/a
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.SelectedIndex = 0;

This reinvokes the SelectedIndexChanged 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

P: n/a
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.comwrote in message
news:jKwlh.780$NO5.752@trndny01...
>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.SelectedIndex = 0;

This reinvokes the SelectedIndexChanged 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

P: n/a
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
SelectedIndexChanged 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 SelectedIndexChanged 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.comwrote in message
news:jKwlh.780$NO5.752@trndny01...
>>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.SelectedIndex = 0;

This reinvokes the SelectedIndexChanged 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

P: n/a
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 SelectIndexChanged 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 SelectIndexChanged 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 SelectIndexChanged 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.comwrote 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
SelectedIndexChanged 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 SelectedIndexChanged 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.comwrote in message
news:jKwlh.780$NO5.752@trndny01...
>>>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.SelectedIndex = 0;

This reinvokes the SelectedIndexChanged 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 #5

P: n/a
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

P: n/a
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 SelectIndexChanged 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 SelectIndexChanged 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 SelectIndexChanged 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.comwrote 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
SelectedIndexChanged 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 SelectedIndexChanged 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.comwrote in message
news:jKwlh.780$NO5.752@trndny01...
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.SelectedIndex = 0;

This reinvokes the SelectedIndexChanged 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 #7

This discussion thread is closed

Replies have been disabled for this discussion.