473,326 Members | 2,438 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,326 software developers and data experts.

'0' is not a valid value for 'SelectedIndex'.

The compiler complains that zero is not acceptable value for selectedIndex.
What I am doing is loading up the combo box with the data from a dataset and
then setting the SelectedIndex value to zero thus forcing the first record to
be selected.

This is an untyped data set and unbound...

Here is a snippet:

private void frmCustomer_Load(object sender, EventArgs e)
{
BindCustomerComboBox();
cbFindName.SelectedIndex = 0;
customer =
CustomerDB.GetCustomer(cbFindName.SelectedValue.To String());
ShowCustomerData();
DisableAddEditMode();

}

private void BindCustomerComboBox()
{
cbFindName.SelectedIndexChanged -=
new System.EventHandler(cbFindName_SelectedIndexChange d);
DataTable customersTable = CustomerDB.GetCustomers();
cbFindName.DataSource = customersTable;
cbFindName.DisplayMember = "cuLastName";
cbFindName.ValueMember = "cuCustomerID";
cbFindName.SelectedIndexChanged +=
new System.EventHandler(cbFindName_SelectedIndexChange d);
}

Nov 16 '05 #1
2 7330
Sorry - Not the compiler but the error is generated at run time

"hodari" wrote:
The compiler complains that zero is not acceptable value for selectedIndex.
What I am doing is loading up the combo box with the data from a dataset and
then setting the SelectedIndex value to zero thus forcing the first record to
be selected.

This is an untyped data set and unbound...

Here is a snippet:

private void frmCustomer_Load(object sender, EventArgs e)
{
BindCustomerComboBox();
cbFindName.SelectedIndex = 0;
customer =
CustomerDB.GetCustomer(cbFindName.SelectedValue.To String());
ShowCustomerData();
DisableAddEditMode();

}

private void BindCustomerComboBox()
{
cbFindName.SelectedIndexChanged -=
new System.EventHandler(cbFindName_SelectedIndexChange d);
DataTable customersTable = CustomerDB.GetCustomers();
cbFindName.DataSource = customersTable;
cbFindName.DisplayMember = "cuLastName";
cbFindName.ValueMember = "cuCustomerID";
cbFindName.SelectedIndexChanged +=
new System.EventHandler(cbFindName_SelectedIndexChange d);
}

Nov 16 '05 #2
Hi,

My guess is that the combobox does not contain any item, why dont you place
a breakpoint in that line and check the Combobox.Items.Count property?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"hodari" <ho****@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.com...
The compiler complains that zero is not acceptable value for
selectedIndex.
What I am doing is loading up the combo box with the data from a dataset
and
then setting the SelectedIndex value to zero thus forcing the first record
to
be selected.

This is an untyped data set and unbound...

Here is a snippet:

private void frmCustomer_Load(object sender, EventArgs e)
{
BindCustomerComboBox();
cbFindName.SelectedIndex = 0;
customer =
CustomerDB.GetCustomer(cbFindName.SelectedValue.To String());
ShowCustomerData();
DisableAddEditMode();

}

private void BindCustomerComboBox()
{
cbFindName.SelectedIndexChanged -=
new System.EventHandler(cbFindName_SelectedIndexChange d);
DataTable customersTable = CustomerDB.GetCustomers();
cbFindName.DataSource = customersTable;
cbFindName.DisplayMember = "cuLastName";
cbFindName.ValueMember = "cuCustomerID";
cbFindName.SelectedIndexChanged +=
new System.EventHandler(cbFindName_SelectedIndexChange d);
}

Nov 16 '05 #3

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

Similar topics

1
by: MickG | last post by:
I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with...
17
by: piraticman | last post by:
Hi. I have some code for a javascript jump menu... It validated with HTML 4.0 but now does not validate with XHTML strict 1.0. I have used name atributes in my code which aparantly are not...
2
by: Alexandre Jaquet | last post by:
Hi, Under IE I could not point why I can't get the selected value from a function here the code function Lvl_P2P(url,closeIt,delay){ //ver1.0 4LevelWebs var fabricant_box; var...
4
by: Emil | last post by:
Can somebody tell me what would be the syntax for having an if statement and setting the selected index of a radiobuttonlist? This is my first project using ASP.net and I use C#. I have a repeater...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
1
by: Nathan Sokalski | last post by:
I have a problem that is driving me crazy. I have a User Control composed of three DropDownLists that will be used to select a date. I have everything working except for one thing. When I select a...
6
by: Nathan Sokalski | last post by:
I am writing a User Control that uses 3 DropDownLists. When I attempt to access the SelectedIndex property it incorrectly reports the value selected by the user. Why is this? Here is my code,...
0
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
by: Andrus | last post by:
To reproduce, run the code. Observed: System.ArgumentOutOfRangeException was unhandled Message="InvalidArgument=Value of '0' is not valid for 'SelectedIndex'.\r\nParameter name: SelectedIndex"...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.