Question

Over here i have an example of implementing matchwithlist in vb.net how ever is there any other ways to do this. In vb the code was simple combo1.matchwithlist The got was taken from http://support.microsoft.com/kb/266265/en-us

Private Sub Combo1_Change()

    Dim listcount As Integer
    Dim textlen As Integer
    Dim matchexists As Boolean

    textlen = Len(Combo1.Text)
    For listcount = 0 To Combo1.listcount - 1
        If UCase(Mid(Combo1.List(listcount), 1, textlen)) = UCase(Combo1.Text) Then
            matchexists = True
            Exit For
        End If
    Next

    If Not matchexists Then
        MsgBox "Value not present in the list... Kindly enter a valid value.."
    End If

End Sub

Private Sub Form_Load()
    Combo1.AddItem "Sam"
    Combo1.AddItem "Paul"
    Combo1.AddItem "Peter"
    Combo1.Text = ""
End Sub
Was it helpful?

Solution

Here's a simple way:

Private Sub ComboBox1_TextChanged(sender As Object, e As System.EventArgs) Handles ComboBox1.TextChanged
    Dim Result As Boolean = False
    For Each itm As String In ComboBox1.Items
        If InStr(itm, ComboBox1.Text, CompareMethod.Text) <> 0 Then
            Result = True
        End If
    Next
    If Not Result Then
        MsgBox("No Match")
    End If
End Sub

This will compare the text entered after each character is typed, and display the messagebox if the text can't be found in any of the combobox items, ignoring case

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top