Home All Groups Group Topic Archive Search About

simple combo question

Author
27 Apr 2006 5:06 PM
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?

Author
27 Apr 2006 5:19 PM
jan.hancic@gmail.com
It will help if you tell us what version of .NET you are using as 2.0
has some new methods that will help you in this task, and 1.1 does
not...


lp
Jan
http://cwizo.blogspot.com
Author
27 Apr 2006 5:25 PM
Tim
..net2 (vs2005)

thanks
Author
27 Apr 2006 9:40 PM
Tim
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.
Author
28 Apr 2006 7:57 AM
jan.hancic@gmail.com
You can select a item by its value like this:

Me.comboBox.Items.FindByValue(YourValue.ToString()).Selected = True

Author
29 Apr 2006 4:08 AM
Chris Chilvers
On 27 Apr 2006 14:40:16 -0700, "Tim" <Citizen10Be***@gmail.com> wrote:

>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?