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

G

Guest

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.ToString());
ShowCustomerData();
DisableAddEditMode();

}

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

Ignacio Machin \( .NET/ C# MVP \)

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top