请问有什么办法解决VB6中combobox实时显示查找结果的问题?
2个回答
2012-08-24
展开全部
最讨厌回答匿名提问,回答一被吞掉,一身的力气都白搭,今天我也匿名回答一下,管他能不能提交去
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const CB_FINDSTRING = &H14C
Const CB_ERR = (-1)
Private Sub Combo1_KeyPress(KeyAscii As Integer)
Dim Temp As Long: Dim MyStr As String
If Combo1.SelLength = 0 Then
MyStr = Combo1.Text & Chr(KeyAscii)
Else
MyStr = Left(Combo1.Text, Combo1.SelStart) & Chr(KeyAscii)
End If
Temp = SendMessage(Combo1.hwnd, CB_FINDSTRING, True, ByVal MyStr)
If Temp <> CB_ERR Then
Combo1.ListIndex = Temp
Combo1.SelStart = Len(Combo1.Text)
End If
KeyAscii = 0
End Sub
Private Sub Form_Load()
Combo1.AddItem "中华人民共和国"
Combo1.AddItem "美国"
Combo1.AddItem "湖南省"
Combo1.AddItem "衡阳市"
End Sub
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const CB_FINDSTRING = &H14C
Const CB_ERR = (-1)
Private Sub Combo1_KeyPress(KeyAscii As Integer)
Dim Temp As Long: Dim MyStr As String
If Combo1.SelLength = 0 Then
MyStr = Combo1.Text & Chr(KeyAscii)
Else
MyStr = Left(Combo1.Text, Combo1.SelStart) & Chr(KeyAscii)
End If
Temp = SendMessage(Combo1.hwnd, CB_FINDSTRING, True, ByVal MyStr)
If Temp <> CB_ERR Then
Combo1.ListIndex = Temp
Combo1.SelStart = Len(Combo1.Text)
End If
KeyAscii = 0
End Sub
Private Sub Form_Load()
Combo1.AddItem "中华人民共和国"
Combo1.AddItem "美国"
Combo1.AddItem "湖南省"
Combo1.AddItem "衡阳市"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询