Solved

Select item in combobox

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
A short article about a problem I had getting the GPS LocationListener working.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now