PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
How do I Select Combobox Value
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
How do I Select Combobox Value
![]() |
How do I Select Combobox Value |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

