当前位置:编程学习 > VB >>

求Combo1控件得用法

如何在Combo1控件上输入文本时,自动打开下拉框,如果下拉框中有我输入的文本则自动选中。

例如如何实现:在Combo1上输入个字母“a”,则可以自动把以“a”开头的英文单词顺序的在下拉列表中显示出来 --------------------编程问答-------------------- 这个有点问题:
COMBO的列表是靠ADDITEM加上去的,如果要显示同一字母开头的,没问题,但显示后,其他的内容就不在这个COMBO控件中了,需要在其他时间或事件中重新加载列表。 --------------------编程问答-------------------- '组合框列表增量查找
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 --------------------编程问答-------------------- 用text box框和list box框组合起来
接收chang事件,显示list 


combo框,应该不行吧。
--------------------编程问答-------------------- ComboIncrementalSearch这个方法,在哪里调用???? --------------------编程问答-------------------- IE中的Combo1框就是这样的。支持! --------------------编程问答-------------------- 可以在 Combo 的 KeyPress 事件中调用。 --------------------编程问答-------------------- '请添加 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

--------------------编程问答-------------------- 这个简单啊,网上搜一下就得到答案了. --------------------编程问答-------------------- 接分先!
补充:VB ,  控件
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,