Results 1 to 4 of 4

Thread: Search as we go

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    Search as we go

    Have a text box and a list view..
    need to enter letters in text box and have names in list box
    move up as I type... Any ideas?

    Thanks

  2. #2
    Hyperactive Member
    Join Date
    May 2003
    Posts
    401

    Re: Search as we go

    Could you be little more clear??? What do u mean by: need to enter letters in text box and have names in list box ???
    Enjoy!!!
    apps_tech

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617
    list box contains a list of names first and last from db
    want to implement a "soft-seek"...

    If I enter n in text box..I would like items with names that start with letter n to popup and so on...

    Thanks

  4. #4
    Hyperactive Member
    Join Date
    May 2003
    Posts
    401
    This is a code I have for now for a combobox. If I enter "East" for example, I would bring all the addresses that start with E then EA then EAS then EAST narrowing the list as I continues. change cmboMyCombo to the name of your combo box.. also make sure the style property is set to 0. I guess this can get u at start as to how to work for ur problem....I am in office right now and do not have VB on my machine to give a working example. Since u said u want the data from database...u need to connect to backend before using the code. Then in your code u should always loop thru the backend for the results.

    I hope this gets u a start..

    VB Code:
    1. 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
    2.  
    3. Private Const CB_FINDSTRING = &H14C
    4. Private Const CB_ERR = (-1)
    5.  
    6. Private Function AutoComplete(ByRef CB As ComboBox, ByVal KeyAscii As Integer, Optional ByVal LimitToList As Boolean = False)
    7.  
    8. Dim FindMatch As Long
    9. Dim ComboEntry As String
    10.  
    11. On Error GoTo ErrRtn
    12.     If KeyAscii = 8 Then
    13.         If CB.SelStart <= 1 Then
    14.             CB.Text = ""
    15.             AutoComplete = 0
    16.             Exit Function
    17.         End If
    18.         If CB.SelLength = 0 Then
    19.             ComboEntry = UCase(Left(CB, Len(CB) - 1))
    20.         Else
    21.             ComboEntry = Left$(CB.Text, CB.SelStart - 1)
    22.         End If
    23.     ElseIf KeyAscii < 32 Or KeyAscii > 127 Then
    24.         Exit Function
    25.     Else
    26.         If CB.SelLength = 0 Then
    27.             ComboEntry = UCase(CB.Text & Chr$(KeyAscii))
    28.         Else
    29.             ComboEntry = Left$(CB.Text, CB.SelStart) & Chr$(KeyAscii)
    30.         End If
    31.     End If
    32.     FindMatch = SendMessage(CB.hWnd, CB_FINDSTRING, -1, ByVal ComboEntry)
    33.  
    34.     If FindMatch <> CB_ERR Then
    35.         CB.ListIndex = FindMatch
    36.         CB.SelStart = Len(ComboEntry)
    37.         CB.SelLength = Len(CB.Text) - CB.SelStart
    38.         AutoComplete = 0
    39.     Else
    40.         If LimitToList = True Then
    41.             AutoComplete = 0
    42.         Else
    43.             AutoComplete = KeyAscii
    44.         End If
    45.     End If
    46.     Exit Function
    47. ErrRtn:
    48.     AutoComplete = 0
    49. End Function
    50.  
    51. Private Sub cmboMyCombo_KeyPress(KeyAscii as Integer)
    52.     KeyAscii = AutoCompelte(cmboMyCombo,KeyAscii,True)
    53. End Sub
    Enjoy!!!
    apps_tech

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