Select item in combobox

Posted on 2009-07-08
Medium Priority
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")))
'// 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

Question by:conrad2010
  • 2
LVL 18

Expert Comment

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


Author Comment

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

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

Expert Comment

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

ComboBox1.SelectedIndex = 3

Accepted Solution

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

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

An ASP.NET Web Form User Control is not newly introduced in ASP.NET. In fact, it was an old technology yet still playing a role to generate web content, especially when we want to use it to have a better and easy way to control part of the web conte…
This article describes and provides a custom-made tool I wrote to give businesses a means of identifying commercial music content, without having to expend too much effort. Business recordings are easily identified from possibly illegal music files …
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 …
Six Sigma Control Plans

624 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