有个录入窗口,里面有一个组合框,本身他作为一个选择框,下拉有很多内容,这样一个个看很难找到。我想在组合框中如果写了简单的内容,如果包含此内容的数据会显示出来。但是如果是没有那么就作为新记录,出来新的录入界面。

解决方案 »

  1.   

    '组合框列表增量查找(英文好用)
    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
      

  2.   

    中文,试试:
    Private Declare Function SendMessagebyString Lib _
    "user32" Alias "SendMessageA" (ByVal hWND As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, _
    ByVal lParam As String) As LongPrivate Const LB_FINDSTRINGEXACT = &H1A2    '在 ListBox 中精确查找
    Private Const CB_FINDSTRINGEXACT = &H158    '在 ComboBox 中精确查找
    Private Const LB_FINDSTRING = &H18F         '在 ListBox 中模糊查找
    Private Const CB_FINDSTRING = &H14C         '在 ComboBox 中模糊查找Private Combo1_Change()
    Dim n As Longn = SendMessagebyString(Combo1.hWnd, CB_FINDSTRING, -1, Combo1.Text)
    If n >= 0 Then Combo1.ListIndex = nEnd Sub