请问在VB中,LISTBOX控件的如何能实现:当你输入一个字符后,会马上在列表中定位到最相近的字符串上。大家帮帮我呀,,,,

解决方案 »

  1.   

    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
    Private m_bEditFromCode As Boolean
    Public Const CB_FINDSTRING = &H14C '查找 ComboBox 中相符项'组合框自动完成功能
    Private Sub cboChange_AutoComplete(cbo As ComboBox)
       Dim i As Long, j As Long
       Dim strPartial As String, strTotal As String
          If m_bEditFromCode Then
             m_bEditFromCode = False
             Exit Sub
          End If
       With cbo
             strPartial = .Text
             i = SendMessage(.hwnd, CB_FINDSTRING, -1, ByVal strPartial)
          If i <> CB_ERR Then
                strTotal = .List(i)
                j = Len(strTotal) - Len(strPartial)
             If j <> 0 Then
                m_bEditFromCode = True
                .SelText = Right$(strTotal, j)
                .SelStart = Len(strPartial)
                .SelLength = j
             Else
             End If
          End If
       End With
    End Sub