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?