472,328 Members | 1,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

combobox selectedindexchanged 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.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
6 10628
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
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
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
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
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 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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...
0
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...
3
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)...
7
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...
5
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...
7
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...
2
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...
0
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...
2
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...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.