注册 登录
编程论坛 VB6论坛

VB6中combo下拉菜单的模糊查找方法

loloxy 发布于 2017-10-27 22:41, 2142 次点击
Private Sub Combo2_Change()
 Dim V2 As String
 Dim IK As Integer
V2 = Combo2.Text
For IK = 0 To Combo2.ListCount - 1
If Combo2.List(IK) Like V2 & "*" Then
Combo2.Text = Combo2.List(IK):
Combo2.SelStart = Len(V2):
Combo2.SelLength = Len(Combo2.Text) - Len(V2):
End If
Next
End Sub
这个代码运行后,我在combo2中输入文字可以进行模糊查找,可是一旦输错想重新输入就无法删除了,各位老师们,这个问题怎么解决啊,谢谢!
1 回复
#2
booksoon2017-10-31 09:58
Private Sub Combo2_Change()

Dim V2 As String
Dim IK As Integer
V2 = Combo2.Text
If Len(Trim(V2)) = 0 Then
    Exit Sub
End If

For IK = 0 To Combo2.ListCount - 1
    If Combo2.List(IK) Like V2 & "*" Then
        Combo2.Text = Combo2.List(IK):
        Combo2.SelStart = Len(V2):
        Combo2.SelLength = Len(Combo2.Text) - Len(V2):
        Exit For
    End If
Next

End Sub

如果按你的想法,应该是这个样的吧
1