470,636 Members | 1,365 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,636 developers. It's quick & easy.

Combo box weirdness

Hi,
I have a combo box that is bound AFTER a user makes a selection from another
unbound drop down. The problem is, the SelectedIndex of the combo box is
always initialized to 0, not -1. This makes it difficult to determine
whether an item was selected or not, since the items collection is Zero based
also. Additionally, in the code that does the binding, when i set the
Datasource, Valuemember and DisplayMember properties, the SelectedIndexChange
AND SelectedValueChange events always fire...given the above two issues, this
makes it difficult to work with the combobox and i fear i am forced to head
back to the old days when i had to set a member variable flag to distinguish
between when i am initializing a combo box and when the user actually is
making a selection...very nasty and backwards. Any ideas on whether this is
a bug or whether this is my issue? the code to initialize the Combo box is
als follows (i am using VS2005 beta):

cbExchange.DataSource = DbConnection.instance.getDbTable(
"StockExchange" );
cbExchange.ValueMember = "exchange_id";
cbExchange.SelectedIndex = -1;
cbExchange.DisplayMember = "symbol";
Nov 16 '05 #1
1 2467
Hello dimension,

Why don't you insert a blank item to index 0? Then you know SelectedIndex
means nothing has been selected.
Hi,
I have a combo box that is bound AFTER a user makes a selection from
another
unbound drop down. The problem is, the SelectedIndex of the combo box
is
always initialized to 0, not -1. This makes it difficult to determine
whether an item was selected or not, since the items collection is
Zero based
also. Additionally, in the code that does the binding, when i set the
Datasource, Valuemember and DisplayMember properties, the
SelectedIndexChange
AND SelectedValueChange events always fire...given the above two
issues, this
makes it difficult to work with the combobox and i fear i am forced to
head
back to the old days when i had to set a member variable flag to
distinguish
between when i am initializing a combo box and when the user actually
is
making a selection...very nasty and backwards. Any ideas on whether
this is
a bug or whether this is my issue? the code to initialize the Combo
box is
als follows (i am using VS2005 beta):
cbExchange.DataSource = DbConnection.instance.getDbTable(
"StockExchange" );
cbExchange.ValueMember = "exchange_id";
cbExchange.SelectedIndex = -1;
cbExchange.DisplayMember = "symbol";

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Corne' Cornelius | last post: by
1 post views Thread by (Pete Cresswell) | last post: by
5 posts views Thread by Phil Weber | last post: by
5 posts views Thread by David Thielen | last post: by
1 post views Thread by Jayyde | last post: by
1 post views Thread by rhino | last post: by
2 posts views Thread by JYA | last post: by
1 post views Thread by Korara | last post: by
???
reply views Thread by Stoney L | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.