C# ComboBox SelectedItem [closed]
- by Diane
I have a combobox with a list of values. I would like the selected index to be a value from the database. I first create the combobox, fill it with values from a dataset like this:
ComboBox cmb_Relay = new ComboBox();
cmb_Relay.DataSource = ds2.Tables[0];
cmb_Relay.DisplayMember = "Relay";
cmb_Relay.ValueMember = "Relay";
Next, I set the SelectedIndex to the value of a specific field value:
cmb_Relay.SelectedItem = ds2.Tables[0].Rows[j][2];
I get the follwing error:
InvalidArgument=Value of '3' is not valid for 'SelectedIndex'.
Parameter name: SelectedIndex