Solved

Select item in combobox

Posted on 2009-07-08
4
783 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
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Injector with Web Service 4 43
Need to start a web service from Visual Studio 2015 Pro 2 25
Store results in vb.net 3 22
Sending receiving text messages in vb.net 15 38
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

831 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