473,387 Members | 1,517 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,387 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 2473
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris | last post by:
I have a drop down list that is databound to a custom collection. When the page loads it populates the drop down list properly with all the values. I have the drop down list set to autopost back....
4
by: mr_burns | last post by:
hi, using javascript, how do i select an option in a combo box? i have tried looking on the internet but dont really know what i should be searching for. what i want to happen is that when a...
5
by: Harry Haller | last post by:
<select name="cboPlaces" id="cboPlaces"> <option value="3">Countryside</option> <option value="4">Forest</option> <option value="5">Mountain</option> <option value="6">Desert</option> <option...
8
by: CZERNAI | last post by:
Hi Am new to programming and to this process of asking questions. I believe I have read all the threads concerning combo box questions but haven't found an answer to my problem. I am using ...
1
by: Brad Allison | last post by:
This is a newbie question. I have a combo box in where the end user will select an item (an obedience class - yes for dogs, not for developers) and then assign an obedience judge to that class. ...
8
by: VB User | last post by:
I would like the text property of combo box to read the first item of the list on form load. I have a set of four items in the collection. How do I do it? Thanks
4
by: Mark L. Breen | last post by:
Hello Guys and Galls, I use combos on my forms. The code to initialise the combos is as follows Dim dsPIDTypes As DataSet dsPIDTypes = PartDB.GetPIDTypes ' Returns a dataset object...
9
by: Kay | last post by:
Hi all, Could you tell me the best way to add a blank item(as first item) in a data binded combo box? Because I think I didn't do it right and it generate an error if the second item(after the...
6
by: =?Utf-8?B?amVmZmVyeQ==?= | last post by:
i need help with a combo box and this same code works on my first tab with a combo box. The error or problem i have is this code causes an index out of range error when i run it on my second combo...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.