Solved

Select item in combobox

Posted on 2009-07-08
4
788 Views
Last Modified: 2012-08-13
how can I select an item in a combobox filled with items?

I am using KeyValuePairs (see attached code).

Say I have 100 items in the combobox and if a project exists, the form loads with that project selected...
'// fill the combobox with KeyValuePairs
 
For i As Integer = 0 To datatable.Rows.Count - 1
                combobox1.Items.Add(New clsKeyValuePair(datatable.Rows(i).Item("PROJECT_ID"), datatable.Rows(i).Item("PROJECT_NAME")))
Next
 
'// KeyValuePairs class
Public Class clsKeyValuePair
 
    Public Key As Object
    Public Value As String
 
    Public Sub New(ByVal NewValue As Object, ByVal NewDescription As String)
        Key = NewValue
        Value = NewDescription
    End Sub
 
    Public Overloads Overrides Function ToString() As String
        Return Value
    End Function
 
End Class

Open in new window

0
Comment
Question by:conrad2010
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 24806737
dim kv as clsKeyValuePair
kv= combobox1.selecteditem


0
 

Author Comment

by:conrad2010
ID: 24806889
it's the other way around...

I load kv from the database and show it as selected in the combobox...
0
 
LVL 2

Expert Comment

by:lppperes
ID: 24806966
If you know the index, you can use the SelectedIndex property

ComboBox1.SelectedIndex = 3
0
 
LVL 2

Accepted Solution

by:
lppperes earned 500 total points
ID: 24807011
With the description, you can try this:

        ComboBox1.SelectedIndex = ComboBox1.FindStringExact("PROJECT X")
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question