求Combo1控件得用法

wanchuxu 2008-03-10 03:38:16
如何在Combo1控件上输入文本时,自动打开下拉框,如果下拉框中有我输入的文本则自动选中。

例如如何实现:在Combo1上输入个字母“a”,则可以自动把以“a”开头的英文单词顺序的在下拉列表中显示出来
...全文
792 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
knowledge_Is_Life 2008-05-01
  • 打赏
  • 举报
回复
接分先!
meiZiNick 2008-04-30
  • 打赏
  • 举报
回复
这个简单啊,网上搜一下就得到答案了.
cbm6666 2008-03-13
  • 打赏
  • 举报
回复
'请添加 Combo1

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 CB_SHOWDROPDOWN = &H14F
Dim i&, aa$, Tmpstr$(), FindIt As Boolean

Private Sub Form_Load()
Combo1.AddItem "a"
Combo1.AddItem "apple"
Combo1.AddItem "b"
Combo1.AddItem "banana"
Combo1.AddItem "baidu"
Combo1.AddItem "c"
Combo1.AddItem "cs"
Combo1.AddItem "年"
Combo1.AddItem "年龄"
Combo1.AddItem "csd"
Combo1.AddItem "csdn"
For i = 0 To Combo1.ListCount - 1
ReDim Preserve Tmpstr$(i)
Tmpstr(i) = Combo1.List(i)
Next
Call SendMessage(Combo1.hwnd, CB_SHOWDROPDOWN, 1, ByVal 0&)
End Sub

Private Sub Combo1_Change()
aa = Combo1.Text
FindIt = False
For i = 0 To Combo1.ListCount - 1
If InStr(1, Tmpstr(i), aa) > 0 Then FindIt = True: Me.Caption = aa & " 已找到,请继续输入下个字": Exit For
Next i
If FindIt = False Then
Combo1.Text = Mid(Combo1.Text, 1, Len(aa) - 1)
Combo1.SelStart = Len(aa)
Me.Caption = "无匹配字符请重新输入"
End If
End Sub

Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Call SendMessage(Combo1.hwnd, CB_SHOWDROPDOWN, 1, ByVal 0&)
End Sub

of123 2008-03-13
  • 打赏
  • 举报
回复
可以在 Combo 的 KeyPress 事件中调用。
东方之珠 2008-03-13
  • 打赏
  • 举报
回复
IE中的Combo1框就是这样的。支持!
tubo_true 2008-03-13
  • 打赏
  • 举报
回复
ComboIncrementalSearch这个方法,在哪里调用????
tubo_true 2008-03-13
  • 打赏
  • 举报
回复
用text box框和list box框组合起来
接收chang事件,显示list


combo框,应该不行吧。
of123 2008-03-13
  • 打赏
  • 举报
回复
'组合框列表增量查找
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long


Public Sub ComboIncrementalSearch(cbo As ComboBox, KeyAscii As Integer)
Static dTimerLast As Double
Static sSearch As String
Static hWndLast As Long
Dim nRet As Long
Const MAX_KEYPRESS_TIME = 0.5

' Weed out characters that are not scanned
If (KeyAscii < 32 Or KeyAscii > 127) Then Exit Sub
If (Timer - dTimerLast) < MAX_KEYPRESS_TIME And hWndLast = cbo.hWnd Then
sSearch = sSearch & Chr$(KeyAscii)
Else
sSearch = Chr$(KeyAscii)
hWndLast = cbo.hWnd
End If

' Search the combo box
nRet = SendMessage(cbo.hWnd, CB_FINDSTRING, -1, ByVal sSearch)
If nRet >= 0 Then
cbo.ListIndex = nRet
End If

KeyAscii = 0
dTimerLast = Timer
End Sub
onetiger1243 2008-03-13
  • 打赏
  • 举报
回复
这个有点问题:
COMBO的列表是靠ADDITEM加上去的,如果要显示同一字母开头的,没问题,但显示后,其他的内容就不在这个COMBO控件中了,需要在其他时间或事件中重新加载列表。

1,453

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧