I made this up with a lot of testing and playing. I didn't want to use API (I am always scared if I use to much API my app won't work on another win version).
AddressBar is my ComboBox.
VB Code:
Private Sub AddressBar_KeyUp(KeyCode As Integer, Shift As Integer) ' Set UserTyped as what the user themselves have typed UserTyped = AddressBar.Text ' Action is based on current key press Select Case KeyCode ' If the keypress is Left, Right, ' Up, Down, PgUp, PgDown ' Back and Ctrl, then just exit sub Case vbKeyLeft, vbKeyRight, vbKeyUp, vbKeyDown, vbKeyShift, vbKeyEscape, vbkeydel, vbKeyPageUp, vbKeyPageDown, vbKeyBack, vbKeyControl Exit Sub ' Another key was pressed so lets try to fill in ' Addressbar if there is a simular address Case Else ' TopIndex holds the index that is currently at the top ' of the combobox (Favorites). Even thought the combobox ' does not expand it is automatically scrolling to whatever ' is the closest text in it's list to what is typed ' in the box. So TopIndex will hold either the first ' item in the list or whatever it thinks is the closest ' to what is being typed ' ' If TopIndex is greater than 0 the combobox (Favorites) ' has found simular text in it's list ' OR ' If TopIndex is still 0 we want to see if it is becuase the user ' is typing something simular to what is in index 0 If ((AddressBar.TopIndex > 0) Or (InStr(1, AddressBar.List(AddressBar.TopIndex), UserTyped))) Then ' Make the Addressbar.Text hold what the user has typed ' and what the computer things is like it AddressBar.Text = UserTyped & Mid(AddressBar.List(AddressBar.TopIndex), Len(UserTyped) + 1, Len(AddressBar.List(AddressBar.TopIndex))) ' Set the starting point of selection to after what ' the user typed AddressBar.SelStart = Len(UserTyped) ' The length of selection is to the end AddressBar.SelLength = Len(AddressBar.Text) - Len(UserTyped) End If End Select End Sub
It checks the ComboBox to see if any item in it compares to what is being typed.
If so it then adds it to the end of what is being typed and selects the text that is being added so the user can continue to type over it.
Of course there are tons of things you can do the add to this but it is a working example.
Let me know if this helps anyone
Mike




Reply With Quote