PDA

Click to See Complete Forum and Search --> : Looking for a Type-Ahead Example


Ed Duval
Nov 11th, 1999, 07:39 AM
I am trying to create a type-ahead which is similar to the "Microsoft Money" look and feel.

I am using a combo-box and essentially have everything worked out by using the KeyPress event. The problem I am having is that the keypress event does not give me the .selposition upon entry. I need to find out where the cursor is within the text of the combo box, hopefully without attempting to track all arrow keys and backspaces, ect.

Does anyone no of any examples or have any code to locate the cursor postion within the combo text?

Here is my code so far:


Private Sub BatchCombo_KeyPress(Index As Integer, KeyAscii As Integer)
ProcessCombo BatchCombo(Index), KeyAscii
KeyAscii = 0
End Sub


Sub ProcessCombo(TestCombo As Control, KeyAscii As Integer)

Dim strText As String
Dim intCtr As Integer

If Len(TestCombo.Tag) > Len(TestCombo.Text) Then TestCombo.Tag = TestCombo.Text

If KeyAscii = 8 Then
If Len(TestCombo.Tag) > 0 Then
TestCombo.Tag = Left(TestCombo.Tag, Len(TestCombo.Tag) - 1)
End If
Else
TestCombo.Tag = TestCombo.Tag + Chr(KeyAscii)
End If
TestCombo.Text = TestCombo.Tag

For intCtr = 0 To TestCombo.ListCount - 1
If UCase(TestCombo.Tag) = UCase(Left(TestCombo.List(intCtr), Len(TestCombo.Tag))) Then
TestCombo.Text = TestCombo.List(intCtr)
TestCombo.SelStart = Len(TestCombo.Tag)
Exit Sub
End If
Next intCtr
TestCombo.Text = TestCombo.Tag
End Sub

Aaron Young
Nov 11th, 1999, 09:51 AM
Try something like this:

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 Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim iIndex As Integer
Dim iStart As Integer
iStart = Combo1.SelStart
iIndex = SendMessage(Combo1.hwnd, CB_FINDSTRING, 0, ByVal Combo1.Text)
If iIndex > -1 And KeyCode <> vbKeyDelete And KeyCode <> vbKeyBack Then
Combo1 = Combo1.List(iIndex)
Combo1.SelStart = iStart
Combo1.SelLength = Len(Combo1)
End If
End Sub



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net