Set combobox's value member programmatically
combobox, selectedvalue, vb.net, visual-studio-2012
Solution
You're close on your second try -- replace SelectedItem with SelectedIndex:
cboCountry.SelectedIndex = cboCountry.FindString(row.Item("CCCOUNTRY").ToString)
Problem
I've been looking around for this answer. Checked here: How to set a combobox value but I'm not sure if it applies to me (could be wrong, please correct me if I am). I'm using VB.Net, VS2012 and I need to programmatically set the value member of a combobox that is databound. My code now is as follows (this is from within a loop assigning a bunch of controls values): ``` cboCountry.SelectedValue = row.Item("CCCOUNTRY").ToString ``` This does not assign any selected value. I have also tried: ``` cboCountry.SelectedItem = cboCountry.FindString(row.Item("CCCOUNTRY").ToString) ``` But this does not work either. For this instance: - I have one combobox - It has two values databound in it's valuemember properties, "US", and "CA" - The row item that I'm assigning it is one of those values. Again, all I need to do is set the selectedvalue programmatically. Any help greatly appreciated!