• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

How to find an item in a combo box

Hello I have a  string value.

Is there any way of finding the string value in a combo box and setting that item as the item that is displayed. Would anybody have any code to do this.

Thanks

Anwar
0
anwarmir
Asked:
anwarmir
1 Solution
 
RonaldBiemansCommented:
something like this
        ComboBox1.SelectedIndex = ComboBox1.Items.IndexOf("yourstring")
0
 
willcode4coffeeCommented:
I think that if the value is in the combo box list you can just set the value and it will match it...just as if you typed it in.

ComboBox1.Value = "YourString"

M@
0
 
koruzicaCommented:
Private Sub searchCombobox1(ByVal strSearch As String)
        For Each itm As String In ComboBox1.Items
            'lets give priority to: begins with...
            If itm.StartsWith(strSearch) Then
                ComboBox1.SelectedIndex = ComboBox1.Items.IndexOf(itm)
                Exit Sub
            End If
        Next

        For Each itm As String In ComboBox1.Items
            'ok, we didn't find any first occurances so...
            If itm.IndexOf(strSearch) > 0 Then
                ComboBox1.SelectedIndex = ComboBox1.Items.IndexOf(itm)
                Exit Sub
            End If
        Next

    End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
karthikeyanTPCommented:

Try this

  cboBox1.SelectedIndex = cboBox1.FindString("your String here")
0
 
koruzicaCommented:
Oops, how did i miss that :)

0
 
karthikeyanTPCommented:
Hai anwarmir,

Does it work?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now