473,320 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 10760
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 item in the combbox not the combbox itself. Any...
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 get the default "comboBox1_SelectedIndexChanged"...
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) { ... comboBox.DataSource = data;...
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 I loop through the items in the Combo looking...
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 control. I have an issue that occurs only when i...
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 the combobox fill is causing the...
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 value from the combobox by using...
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 exist in .Net yet, but I'm guessing it will in...
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 Loademails() function. I then call it again in the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.