473,795 Members | 3,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 StateAbbreviati on FROM States ORDER BY StateAbbreviati on";

//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.CreateD ataSetFromSQL(S QL).Tables[0];
this.cboOrigin. DisplayMember = "StateAbbreviat ion";
this.cboOrigin. ValueMember = "StateAbbreviat ion";
this.cboOrigin. SelectedIndex = -1;

If I place an OnSelectedIndex Changed() 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 2493
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 StateAbbreviati on FROM States ORDER BY StateAbbreviati on";

//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.CreateD ataSetFromSQL(S QL).Tables[0];
this.cboOrigin. DisplayMember = "StateAbbreviat ion";
this.cboOrigin. ValueMember = "StateAbbreviat ion";
this.cboOrigin. SelectedIndex = -1;

If I place an OnSelectedIndex Changed() 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
286
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. In the form load I if the it is a post back I am able to print the appropriate index of the selected index for the drop down box. However the combo box is still showing the first item in the list as being selected no matter which item I actually...
4
8845
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 function is called a line of code will select a specific option in a combo box. something like: //excuse the dodgy syntax
5
17217
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 value="7">Jungle</option> <option value="7">Swamp</option> <option value="8">River</option> <option value="12">Town</option> <option value="9">Sea</option>
8
2927
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 "combobox.items.add(combobox.text)" to add an item to the collection of the combo box. When the program runs I can see the new item in the combo box (hi-lited) but when i close the form the new item doesn't stay in the collection.
1
1909
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. When they save this record, I do not want that class in the combo box to be enabled. Is there a way to 'disable' this selection only, while keeping the other classes available to the user. And then on the flip side, if the user deletes that...
8
6104
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
1767
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 cboPIDType.DataSource = dsPIDTypes cboPIDType.DisplayMember = "tlkpPIDType.PT_Type"
9
4463
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 top blank item) is selected by using Combo.SelectedValue : "Specified argument was out of the range of valid values. Parameter name: '-2147483648' is not a valid value for 'index'.
6
1875
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 box: (errored code) Select Case ComboBox2.text Case Is ="Execute Program" 'code to execute program here Case Is ="Other Command that executes code at a certain time" ' code below the same as above except that it works But not my first(this...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.