PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms How do I Select Combobox Value

Reply

How do I Select Combobox Value

 
Thread Tools Rate Thread
Old 01-06-2005, 05:54 PM   #1
=?Utf-8?B?S2VudEc=?=
Guest
 
Posts: n/a
Default How do I Select Combobox Value


I'm trying to select a value from a combobox but I'm not able to get the
combobox to change (it just stays blank) :

Me.cboDiagnosis.SelectedItem = 5

I've set the ValueMember and DisplayMember when I binded..and I know there
is a ValueMember = 5 but I can't select it...what am I doing wrong?

Thanks,
Kent.
  Reply With Quote
Old 01-06-2005, 08:44 PM   #2
Lee Gillie
Guest
 
Posts: n/a
Default Re: How do I Select Combobox Value

KentG wrote:
> I'm trying to select a value from a combobox but I'm not able to get the
> combobox to change (it just stays blank) :
>
> Me.cboDiagnosis.SelectedItem = 5
>
> I've set the ValueMember and DisplayMember when I binded..and I know there
> is a ValueMember = 5 but I can't select it...what am I doing wrong?
>
> Thanks,
> Kent.


What did you bind to? Generally SelectedItem is an object reference.
(this code is not compilable, but I think you will get the idea...)

Example:
Class CBItem
Public mDesc as String
Public mValue as Integer
Public Readonly property DispMem as string
return mDesc
End Property
Public Readonly property ValMem as integer
return mValue
End Property
Public Overrides Function ToString as string
return mDesc
End Property
End Class

Public mArry as New ArrayList
Dim cbi as CBItem
cbi = new CBItem
cbi.mDesc = "This must be the very first one"
cbi.mValue = 1
mArry.Add(cbi)
... etc

Now bind
cbMyCB.DisplayMember = "DispMem"
cbMyCB.ValueMember = "ValMem"
cbMyCB.DataSource = mArry

Now.....

you can set by index
cbMyCB.SelectedIndex = 3 ' 3rd element in your mArry
cbMyCB.SelectedItem = cbi ' Some cbi instance that is in your mArry
cbMyCB.SelectedValue = 2 ' the cbi item in your mArry with an mValue = 2

HTH - Lee
  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off