473,503 Members | 3,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

an error of setting comboBox.SelectedValue

## i have a table like this:

myID myName
------------------------ -----------------------------
1 aaa
2 bbb
3 ccc

## in VS2003, i write code:
//
// step 1: create a dataset, and load data in table1
//
DataSet ds = new DataSet();

SqlDataAdapter da = new SqlDataAdapter(...);
da.Fill(ds, "table");
//
// step 2: add a new datarow at the top of table1
//
DataRow dr = ds.Tables["table1"].NewRow();
dr["myID"] = "0";
dr["myName"] = "<all>";
ds.Tables["table1"].Rows.InsertAt(dr, 0);
ds.Tables["table1"].AcceptChanges();
//
// step 3: bind comboBox1
//
comboBox1.DataSource = ds.Tables["table1"];
comboBox1.DisplayMember = "myName";
comboBox1.ValueMember = "myID";

## it works all right. but when i run following code, an error displayed.

comboBox1.SelectedValue = 1; //error(System.ArgumentOutOfRangeException)

## i modified the code(1->2), no error displayed.

comboBox1.SelectedValue = 2; //no error

## but after removing the step 2, no error occured when i run
"comboBox1.SelectedValue = 1;" .
## i was confused, please help me. thank you in advance.
Nov 16 '05 #1
1 4043
hi chen
do you have the value one in your table ??, if so then this is very
strange behavior , there must be something like order of initialization of
object or something . Would you post a snippet of your code.
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
20750
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well....
12
4684
by: Dica | last post by:
i can't seem to find a way to cast the value in my comboBox to integer. i've tried the following: short iProjectID = Convert.ToInt16(cboProjects.SelectedValue); i keep getting a "Sepcified...
0
4778
by: JSantora | last post by:
Essentially, InsertAT is broken! For the past couple of hours, I've been getting this "Parameter name: '-2147483550' is not a valid value for 'index'." error. Apparently, its caused by having...
5
3169
by: Peter M. | last post by:
I'm struggling with combobox databinding with something I consider a bug... I'm binding my combobox to an array of structs. The struct exposes two public properties, ID and Name, to be used as...
3
1999
by: dbuchanan | last post by:
These setting mystify me for these reasons. *SelectedItem* - Help says that 'SelectedItem' gets or sets the currently selected item in the combobox. *SelectedValue* - Help says that...
0
2058
by: Siv | last post by:
Hi, I have a class that I want to use generically to add items to a combobox so that I have a display item and an ID item that isn't displayed but that I can use to display the relevant database...
4
1326
by: Martin | last post by:
using VS2005 - VB.Net I noticed unexpected behaviour when using a combobox which has it's datasource set to a datatable. Also the Valuemember and Displaymember are being set. I'm getting a cast...
5
5688
by: Crazy Cat | last post by:
Hi all, I have combobox that is bound to a custom object collection thusly Dim collection As List(Of StructureType) = StructureType.FindStructureTypes(SharedObjects.StructureTypes,...
2
2437
by: TG | last post by:
Hi! Once again I have hit a brick wall here. I have a combobox in which the user types the server name and then clicks on button 'CONNECT' to populate the next combobox which contains all the...
0
7192
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
7261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7315
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...
1
6974
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...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3158
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...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1492
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 ...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.