如何在vb中利用输入的文字筛选下拉框中的内容?
4个回答
展开全部
这功能在VB.NET中很好实现,在VB中很麻烦
追问
感谢你的回答,但是我现在是要用vb进行编程
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
vb6 Code
Option Explicit
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 WM_USER = &H400
Const CB_SHOWDROPDOWN = &H14F
Const WM_SETREDRAW As Long = &HB&
Const CB_FINDSTRING As Long = &H14C&
Const CB_SELECTSTRING = &H14D
Public Sub SearchCombo(InControl As Object)
On Error GoTo trap
Dim StrPos As Long
Dim lPos As Long
Dim SearchStr As String
If TypeOf InControl Is ComboBox Then
StrPos = InControl.SelStart
SearchStr = Left$(InControl.Text, StrPos)
lPos = SendMessage(InControl.hwnd, CB_FINDSTRING, 0, ByVal SearchStr)
If lPos >= 0 Then
Dim id As Long
id = SendMessage(InControl.hwnd, CB_FINDSTRING, -1, ByVal CStr(InControl.Text))
If id >= 0 Then
SendMessage InControl.hwnd, CB_SHOWDROPDOWN, 1, 0
SendMessage InControl.hwnd, CB_SELECTSTRING, 1, id
End If
InControl.Text = InControl.List(lPos)
InControl.ListIndex = lPos
End If
With InControl
.SelStart = StrPos
.SelLength = Len(InControl.Text)
End With
End If
Exit Sub
trap:
MsgBox Err.Description
End Sub
Private Sub Form_Load()
Combo1.AddItem "11111"
Combo1.AddItem "22222"
Combo1.AddItem "33333"
Combo1.AddItem "44444"
Combo1.AddItem "55555"
Combo1.AddItem "66666"
Dim nret As Long
nret = SendMessage(Combo1.hwnd, CB_SHOWDROPDOWN, 1, ByVal 0&)
End Sub
'法一
Private Sub Combo1_Change()
Call SearchCombo(Combo1)
End Sub
'法二
Private Sub Combo1_Change()
SendKeys "{F4}"
End Sub
'法三
Private Sub Combo1_Change()
Call SearchCombo(Combo1)
SendKeys "{F4}"
End Sub
Option Explicit
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 WM_USER = &H400
Const CB_SHOWDROPDOWN = &H14F
Const WM_SETREDRAW As Long = &HB&
Const CB_FINDSTRING As Long = &H14C&
Const CB_SELECTSTRING = &H14D
Public Sub SearchCombo(InControl As Object)
On Error GoTo trap
Dim StrPos As Long
Dim lPos As Long
Dim SearchStr As String
If TypeOf InControl Is ComboBox Then
StrPos = InControl.SelStart
SearchStr = Left$(InControl.Text, StrPos)
lPos = SendMessage(InControl.hwnd, CB_FINDSTRING, 0, ByVal SearchStr)
If lPos >= 0 Then
Dim id As Long
id = SendMessage(InControl.hwnd, CB_FINDSTRING, -1, ByVal CStr(InControl.Text))
If id >= 0 Then
SendMessage InControl.hwnd, CB_SHOWDROPDOWN, 1, 0
SendMessage InControl.hwnd, CB_SELECTSTRING, 1, id
End If
InControl.Text = InControl.List(lPos)
InControl.ListIndex = lPos
End If
With InControl
.SelStart = StrPos
.SelLength = Len(InControl.Text)
End With
End If
Exit Sub
trap:
MsgBox Err.Description
End Sub
Private Sub Form_Load()
Combo1.AddItem "11111"
Combo1.AddItem "22222"
Combo1.AddItem "33333"
Combo1.AddItem "44444"
Combo1.AddItem "55555"
Combo1.AddItem "66666"
Dim nret As Long
nret = SendMessage(Combo1.hwnd, CB_SHOWDROPDOWN, 1, ByVal 0&)
End Sub
'法一
Private Sub Combo1_Change()
Call SearchCombo(Combo1)
End Sub
'法二
Private Sub Combo1_Change()
SendKeys "{F4}"
End Sub
'法三
Private Sub Combo1_Change()
Call SearchCombo(Combo1)
SendKeys "{F4}"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的问题还是不太明确,你的下拉框是什么啊
追问
就是dragmode为0的ComboBox
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询