Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Select item in combobox

Posted on 2009-07-08
4
Medium Priority
?
794 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 2000 total points
ID: 24807011
With the description, you can try this:

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

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Simple Linear Regression
Six Sigma Control Plans
Suggested Courses

610 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