471,603 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Unable to set combo box selected item index to -1

B
I'm trying to simply build a form with a combo box containing a list of
states. I'd like for there to be NO default selected item, but invariably,
the first item in the DataSource is being displayed. It seems to work fine
on other forms, but for one particular form, nothing I do seems to work. My
code is basically:

string SQL = "";

SQL = "SELECT StateAbbreviation FROM States ORDER BY StateAbbreviation";

//The Helper method simply builds a DataSet from the provided SQL query. I
then
//set the combo datasource to the first table within the DataSet

this.cboOrigin.DataSource = Helpers.CreateDataSetFromSQL(SQL).Tables[0];
this.cboOrigin.DisplayMember = "StateAbbreviation";
this.cboOrigin.ValueMember = "StateAbbreviation";
this.cboOrigin.SelectedIndex = -1;

If I place an OnSelectedIndexChanged() event handler on the combo box, it
appears as if the index is getting set properly, but ultimately, the first
state abbreviation still appears by default. This is all happening within a
Form_Load() method, and the combo is just a plain
System.Windows.Forms.ComboBox control with the DropDownStyle property set to
DropDownList. Any ideas?
Jan 2 '06 #1
2 2394
Check out the following thread:

http://groups.google.com/group/micro...b9a0389da6094d

There was another thread containing a detailed explanation of why this
happens, but I can't find it at the moment.

Jan 2 '06 #2
B wrote:
I'm trying to simply build a form with a combo box containing a list of
states. I'd like for there to be NO default selected item, but invariably,
the first item in the DataSource is being displayed. It seems to work fine
on other forms, but for one particular form, nothing I do seems to work. My
code is basically:

string SQL = "";

SQL = "SELECT StateAbbreviation FROM States ORDER BY StateAbbreviation";

//The Helper method simply builds a DataSet from the provided SQL query. I
then
//set the combo datasource to the first table within the DataSet

this.cboOrigin.DataSource = Helpers.CreateDataSetFromSQL(SQL).Tables[0];
this.cboOrigin.DisplayMember = "StateAbbreviation";
this.cboOrigin.ValueMember = "StateAbbreviation";
this.cboOrigin.SelectedIndex = -1;

If I place an OnSelectedIndexChanged() event handler on the combo box, it
appears as if the index is getting set properly, but ultimately, the first
state abbreviation still appears by default. This is all happening within a
Form_Load() method, and the combo is just a plain
System.Windows.Forms.ComboBox control with the DropDownStyle property set to
DropDownList. Any ideas?


It's a known bug in .NET 1.1 - install .NET 1.1 Service Pack 1
Jan 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Chris | last post: by
4 posts views Thread by mr_burns | last post: by
8 posts views Thread by CZERNAI | last post: by
1 post views Thread by Brad Allison | last post: by
8 posts views Thread by VB User | last post: by
4 posts views Thread by Mark L. Breen | last post: by
6 posts views Thread by =?Utf-8?B?amVmZmVyeQ==?= | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

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.