?
Solved

Select item in combobox

Posted on 2009-07-08
4
Medium Priority
?
792 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

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 …
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
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 …
Starting up a Project
Suggested Courses

764 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