0

在这里,我有一个在 vb.net 中实现 matchwithlist 的示例,但是还有其他方法可以做到这一点。在 vb 中,代码很简单combo1.matchwithlist 得到的来自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
4

1 回答 1

0

这是一个简单的方法:

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

这将比较输入每个字符后输入的文本,如果在任何组合框项目中都找不到文本,则显示消息框,忽略大小写

于 2013-05-30T08:09:17.573 回答