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:
Again, all I need to do is set the selectedvalue programmatically. Any help greatly appreciated!
You're close on your second try -- replace SelectedItem with SelectedIndex:
cboCountry.SelectedIndex = cboCountry.FindString(row.Item("CCCOUNTRY").ToString)