Vb中列表框控件能否实现输入字母后自动匹配列表框里的选项

2024-12-28 17:10:32
推荐回答(4个)
回答1:

listbox、combobox、filelistbox、dirlistbox等控件天生具有这个功能,不需要你写一行代码!

回答2:

你可以在COMBO的按键事件里 识别按键事件,按什么键 combo1.listinex=... 第二次<多少的话combo1.listinex=combo1.listinex+1

回答3:

可以提供下思路 你可以在截取字符比对。

新手,高手不要喷我。

回答4:

加一个text1,就你第一个例子
Public Function py(mystr As String) As String
If mystr <> "" Then
i = Asc(mystr)
Select Case i
Case -20319 To -20284: py = "A"
Case -20283 To -19776: py = "B"
Case -19775 To -19219: py = "C"
Case -19218 To -18711: py = "D"
Case -18710 To -18527: py = "E"
Case -18526 To -18240: py = "F"
Case -18239 To -17923: py = "G"
Case -17922 To -17418: py = "H"
Case -17417 To -16475: py = "J"
Case -16474 To -16213: py = "K"
Case -16212 To -15641: py = "L"
Case -15640 To -15166: py = "M"
Case -15165 To -14923: py = "N"
Case -14922 To -14915: py = "O"
Case -14914 To -14631: py = "P"
Case -14630 To -14150: py = "Q"
Case -14149 To -14091: py = "R"
Case -14090 To -13319: py = "S"
Case -13318 To -12839: py = "T"
Case -12838 To -12557: py = "W"
Case -12556 To -11848: py = "X"
Case -11847 To -11056: py = "Y"
Case -11055 To -10247: py = "Z"
Case Else: py = mystr
End Select
End If
End Function

Private Sub Text1_Change()
If Text1 <> "" Then
For j = 0 To List1.ListCount - 1
If py(Mid(List1.List(j), Len(Text1), 1)) = UCase(Right(Text1, 1)) Then
List1.ListIndex = j
Exit For
End If
Next
End If
End Sub