Results 1 to 2 of 2

Thread: Look Ahead Combo Box

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Posts
    82

    Exclamation



    I got this code here at VB-World and it's suppose to allow the User to enter a string and it will find the match or at least the nearest match of the string in the Combo Box.

    Private Const CB_FINDSTRING = &H14C
    Private Const CB_ERR = (-1)
    Private Declare Function sendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, wMsg As Long, ByVal wParam As Long, IParam As Any) As Long

    Public Function autoFind(ByRef refComboBox As ComboBox, ByVal KeyAscii As Integer, Optional ByVal LimitToList As Boolean = False) As Long
    Dim ICB As Long
    Dim sFindString As String
    If (KeyAscii = 8) Then
    If (refComboBox.SelStart <= 1) Then
    refComboBox = ""
    autoFind = 0
    Exit Function
    End If
    If (refComboBox.SelLength = 0) Then
    sFindString = UCase(Left(refComboBox, Len(refComboBox) - 1))
    Else
    sFindString = Left$(refComboBox.Text, refComboBox.SelStart - 1)
    End If
    ElseIf ((KeyAscii < 32) Or (KeyAscii > 127)) Then
    Exit Function
    Else
    If (refComboBox.SelLength = 0) Then
    sFindString = UCase(refComboBox.Text & Chr$(KeyAscii))
    Else
    sFindString = Left$(refComboBox.Text, refComboBox.SelStart) & Chr$(KeyAscii)
    End If
    End If
    ICB = sendMessage(refComboBox.hWnd, CB_FINDSTRING, -1, ByVal sFindString)
    If (ICB <> CB_ERR) Then
    refComboBox.ListIndex = ICB
    refComboBox.SelStart = Len(sFindString)
    refComboBox.SelLength = Len(refComboBox.Text) - refComboBox.SelStart
    autoFind = 0
    Else
    If (LimitToList) Then
    autoFind = 0
    Else
    autoFind = KeyAscii
    End If
    End If
    End Function

    What happens though is, whatever I type in, the only string I receive in return is the first item in the Combo Box.

    Please help.

    Thanks.

  2. #2
    Addicted Member
    Join Date
    Mar 2001
    Posts
    157
    This should work
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width