simple combo question

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

it must be tempting to say FTFM, but believe me I have.

I have a combobox.
I set Co.ValueMember = "field1"
and Co.DisplayMember = "field2"

and then load some data this way

Co.DataSource = DS.Tables(1)

so far so good, I now have a combo filled with data.

Now all I need to do is move the combo to an item with code, based on
the ValueMember.

I guessed something like
Co.SelectedValue = "123"

No joy. I have loads of other things as well.

Any tips?
 
if anyone is interested, I have found the answer to my problem!!!

Co.SelectedValue = "123" does indeed work,

However, if you create a new combo at runtime, set the selectedvalue,
and then add it to the form, it fails. If you create a new combo at
runtime, then add it to the form, then set the selectedvalue, it works
fine!

Not sure if this is obvious behaviour or not. Oh well, I'll file it
under Q for quirky.
 
You can select a item by its value like this:

Me.comboBox.Items.FindByValue(YourValue.ToString()).Selected = True
 
if anyone is interested, I have found the answer to my problem!!!

Co.SelectedValue = "123" does indeed work,

However, if you create a new combo at runtime, set the selectedvalue,
and then add it to the form, it fails. If you create a new combo at
runtime, then add it to the form, then set the selectedvalue, it works
fine!

Not sure if this is obvious behaviour or not. Oh well, I'll file it
under Q for quirky.

I belive the drop down list doesn't bind to its data until it's been added to a form. A limitation due to
BindingContext?
 
Back
Top