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

  • Thread starter Thread starter Guest
  • Start date Start date
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);
}
 
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,
 
Back
Top