Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set combobox's value member programmatically

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:

  1. I have one combobox
  2. It has two values databound in it's valuemember properties, "US", and "CA"
  3. 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!

like image 809
jamesdlivesinatree Avatar asked Nov 30 '25 14:11

jamesdlivesinatree


1 Answers

You're close on your second try -- replace SelectedItem with SelectedIndex:

cboCountry.SelectedIndex = cboCountry.FindString(row.Item("CCCOUNTRY").ToString)
like image 109
xpda Avatar answered Dec 03 '25 23:12

xpda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!