Results 1 to 14 of 14

Thread: SoftSeek

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    SoftSeek

    Hello!

    I am loading a combo box with a list of addresses... and would like to jump to an address as I am typing the characters....
    So 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 continue

    Thanks in advance..

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    change cmboMyCombo to the name of your combo box.. also make sure the style property is set to 0

    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    ...

    Ok...
    I have 2 entries

    1000 Rt 2....
    E. 42nd St

    When I type E, I would expect the second entrie to popup at
    top of list and if there were more entries that start with E, they
    would follow those entries as well... Would it do that?

    Once I type E, the first entry shows up

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    post your code exactly how u have it

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    ...

    I just put yours in place

  6. #6
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217

    Re: ...

    Originally posted by Lafor
    Ok...
    I have 2 entries

    1000 Rt 2....
    E. 42nd St

    When I type E, I would expect the second entrie to popup at
    top of list and if there were more entries that start with E, they
    would follow those entries as well... Would it do that?

    Once I type E, the first entry shows up
    you mean sort of like Autocomplete (it only shows possible results instead of irrelevant results) ? There is no automatic code to do it.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    well when i paste this into a form it works
    VB Code:
    1. Option Explicit
    2.  
    3. 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
    4.  
    5. Private Const CB_FINDSTRING = &H14C
    6. Private Const CB_ERR = (-1)
    7.  
    8. Private Function AutoComplete(ByRef CB As ComboBox, ByVal KeyAscii As Integer, Optional ByVal LimitToList As Boolean = False)
    9.  
    10. Dim FindMatch As Long
    11. Dim ComboEntry As String
    12.  
    13. On Error GoTo ErrRtn
    14.     If KeyAscii = 8 Then
    15.         If CB.SelStart <= 1 Then
    16.             CB.Text = ""
    17.             AutoComplete = 0
    18.             Exit Function
    19.         End If
    20.         If CB.SelLength = 0 Then
    21.             ComboEntry = UCase(Left(CB, Len(CB) - 1))
    22.         Else
    23.             ComboEntry = Left$(CB.Text, CB.SelStart - 1)
    24.         End If
    25.     ElseIf KeyAscii < 32 Or KeyAscii > 127 Then
    26.         Exit Function
    27.     Else
    28.         If CB.SelLength = 0 Then
    29.             ComboEntry = UCase(CB.Text & Chr$(KeyAscii))
    30.         Else
    31.             ComboEntry = Left$(CB.Text, CB.SelStart) & Chr$(KeyAscii)
    32.         End If
    33.     End If
    34.     FindMatch = SendMessage(CB.hWnd, CB_FINDSTRING, -1, ByVal ComboEntry)
    35.  
    36.     If FindMatch <> CB_ERR Then
    37.         CB.ListIndex = FindMatch
    38.         CB.SelStart = Len(ComboEntry)
    39.         CB.SelLength = Len(CB.Text) - CB.SelStart
    40.         AutoComplete = 0
    41.     Else
    42.         If LimitToList = True Then
    43.             AutoComplete = 0
    44.         Else
    45.             AutoComplete = KeyAscii
    46.         End If
    47.     End If
    48.     Exit Function
    49. ErrRtn:
    50.     AutoComplete = 0
    51. End Function
    52.  
    53. Private Sub cmboMyCombo_KeyPress(KeyAscii As Integer)
    54.     KeyAscii = AutoComplete(cmboMyCombo, KeyAscii, True)
    55. End Sub
    56.  
    57. Private Sub Form_Load()
    58.     cmboMyCombo.AddItem "1000 Rt 2"
    59.     cmboMyCombo.AddItem "E. 42nd St"
    60. End Sub

    When I type E, I would expect the second entrie to popup at
    top of list and if there were more entries that start with E, they
    would follow those entries as well... Would it do that?
    more entries wont be next unless the combobox it in alphabetical order.. perhaps that is how you should load it.. or set the combos sorted property to true

  8. #8
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819
    This only seems to work if the drop-down section of the combo isn't dropped down. If it is, it seems to find the entry properly (you can see it being selected in the list portion), but when you tab off the combo it goes back to the previously selected item in the list.

    Is it just me?
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  9. #9
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819
    Gentle bump...
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  10. #10
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819
    Slightly less gentle bump...
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  11. #11
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    try this.. place Combo1 on form:

    VB Code:
    1. Option Explicit
    2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
    3. Private Const CB_FINDSTRING = &H14C
    4.  
    5. Const CB_SHOWDROPDOWN As Long = &H14F
    6.  
    7. Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
    8.     Dim b As String
    9.     Dim a As Long
    10.    
    11.     If KeyCode <> 8 And KeyCode <> 13 Then 'backspace and enter
    12.         b = Combo1.Text
    13.         SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, 1, ByVal 0&
    14.         a = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, Combo1.Text)
    15.         If a <> -1 Then
    16.             Combo1.Text = Combo1.List(a)
    17.             Combo1.SelStart = Len(b)
    18.             Combo1.SelLength = 100
    19.         End If
    20.     End If
    21. End Sub
    22.  
    23. Private Sub Form_Load()
    24. With Combo1
    25.     .AddItem "hello"
    26.     .AddItem "bye"
    27.     .AddItem "pineapple"
    28.     .AddItem "apple"
    29.     .AddItem "orange"
    30. End With
    31. End Sub
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  12. #12
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819
    Thanks, Buggy, but that does exactly the same thing. Try this and you'll see what I mean...
    • Select, say "Pineapple" from your combo.
    • Next, click on the down arrow to display the list portion of the combo.
    • While the list is displayed, type in "Ap". That will display "Apple" on the list, and autocomplete the word in the text box.
    • Tab off the combo box. It will revert back to showing "Pineapple".

    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  13. #13
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    no it doesn't.. i did exactly what you said and it didn't revert back to pineapple. it stayed at apple.

    btw if you change
    Combo1.Text = Combo1.List(a)
    to
    Combo1.ListIndex = a

    it will follow the list when you type.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  14. #14
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819
    How very, very odd. It definitely reverts back to pineapple for me. Mind you, this is a very old and sad PC. Maybe I'll try it at home and see if it works properly there.

    Thanks for your help.
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

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