|
-
May 21st, 2003, 09:17 AM
#1
Thread Starter
Fanatic Member
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..
-
May 21st, 2003, 09:41 AM
#2
change cmboMyCombo to the name of your combo box.. also make sure the style property is set to 0
VB Code:
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
Private Const CB_FINDSTRING = &H14C
Private Const CB_ERR = (-1)
Private Function AutoComplete(ByRef CB As ComboBox, ByVal KeyAscii As Integer, Optional ByVal LimitToList As Boolean = False)
Dim FindMatch As Long
Dim ComboEntry As String
On Error GoTo ErrRtn
If KeyAscii = 8 Then
If CB.SelStart <= 1 Then
CB.Text = ""
AutoComplete = 0
Exit Function
End If
If CB.SelLength = 0 Then
ComboEntry = UCase(Left(CB, Len(CB) - 1))
Else
ComboEntry = Left$(CB.Text, CB.SelStart - 1)
End If
ElseIf KeyAscii < 32 Or KeyAscii > 127 Then
Exit Function
Else
If CB.SelLength = 0 Then
ComboEntry = UCase(CB.Text & Chr$(KeyAscii))
Else
ComboEntry = Left$(CB.Text, CB.SelStart) & Chr$(KeyAscii)
End If
End If
FindMatch = SendMessage(CB.hWnd, CB_FINDSTRING, -1, ByVal ComboEntry)
If FindMatch <> CB_ERR Then
CB.ListIndex = FindMatch
CB.SelStart = Len(ComboEntry)
CB.SelLength = Len(CB.Text) - CB.SelStart
AutoComplete = 0
Else
If LimitToList = True Then
AutoComplete = 0
Else
AutoComplete = KeyAscii
End If
End If
Exit Function
ErrRtn:
AutoComplete = 0
End Function
Private Sub cmboMyCombo_KeyPress(KeyAscii as Integer)
KeyAscii = AutoCompelte(cmboMyCombo,KeyAscii,True)
End Sub
-
May 21st, 2003, 09:52 AM
#3
Thread Starter
Fanatic Member
...
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
-
May 21st, 2003, 09:53 AM
#4
post your code exactly how u have it
-
May 21st, 2003, 09:54 AM
#5
Thread Starter
Fanatic Member
...
I just put yours in place
-
May 21st, 2003, 09:56 AM
#6
The picture isn't missing
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  .
-
May 21st, 2003, 10:03 AM
#7
well when i paste this into a form it works
VB Code:
Option Explicit
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
Private Const CB_FINDSTRING = &H14C
Private Const CB_ERR = (-1)
Private Function AutoComplete(ByRef CB As ComboBox, ByVal KeyAscii As Integer, Optional ByVal LimitToList As Boolean = False)
Dim FindMatch As Long
Dim ComboEntry As String
On Error GoTo ErrRtn
If KeyAscii = 8 Then
If CB.SelStart <= 1 Then
CB.Text = ""
AutoComplete = 0
Exit Function
End If
If CB.SelLength = 0 Then
ComboEntry = UCase(Left(CB, Len(CB) - 1))
Else
ComboEntry = Left$(CB.Text, CB.SelStart - 1)
End If
ElseIf KeyAscii < 32 Or KeyAscii > 127 Then
Exit Function
Else
If CB.SelLength = 0 Then
ComboEntry = UCase(CB.Text & Chr$(KeyAscii))
Else
ComboEntry = Left$(CB.Text, CB.SelStart) & Chr$(KeyAscii)
End If
End If
FindMatch = SendMessage(CB.hWnd, CB_FINDSTRING, -1, ByVal ComboEntry)
If FindMatch <> CB_ERR Then
CB.ListIndex = FindMatch
CB.SelStart = Len(ComboEntry)
CB.SelLength = Len(CB.Text) - CB.SelStart
AutoComplete = 0
Else
If LimitToList = True Then
AutoComplete = 0
Else
AutoComplete = KeyAscii
End If
End If
Exit Function
ErrRtn:
AutoComplete = 0
End Function
Private Sub cmboMyCombo_KeyPress(KeyAscii As Integer)
KeyAscii = AutoComplete(cmboMyCombo, KeyAscii, True)
End Sub
Private Sub Form_Load()
cmboMyCombo.AddItem "1000 Rt 2"
cmboMyCombo.AddItem "E. 42nd St"
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
-
Jul 29th, 2003, 04:22 AM
#8
Fanatic Member
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?
-
Jul 29th, 2003, 10:17 AM
#9
Fanatic Member
-
Jul 30th, 2003, 03:53 AM
#10
Fanatic Member
Slightly less gentle bump...
-
Jul 30th, 2003, 03:14 PM
#11
The picture isn't missing
try this.. place Combo1 on form:
VB Code:
Option Explicit
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
Private Const CB_FINDSTRING = &H14C
Const CB_SHOWDROPDOWN As Long = &H14F
Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim b As String
Dim a As Long
If KeyCode <> 8 And KeyCode <> 13 Then 'backspace and enter
b = Combo1.Text
SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, 1, ByVal 0&
a = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, Combo1.Text)
If a <> -1 Then
Combo1.Text = Combo1.List(a)
Combo1.SelStart = Len(b)
Combo1.SelLength = 100
End If
End If
End Sub
Private Sub Form_Load()
With Combo1
.AddItem "hello"
.AddItem "bye"
.AddItem "pineapple"
.AddItem "apple"
.AddItem "orange"
End With
End Sub
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jul 31st, 2003, 08:36 AM
#12
Fanatic Member
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".
-
Jul 31st, 2003, 03:51 PM
#13
The picture isn't missing
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  .
-
Aug 1st, 2003, 05:26 AM
#14
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|