|
-
Nov 11th, 1999, 08:39 AM
#1
Thread Starter
New Member
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
-
Nov 11th, 1999, 10:51 AM
#2
Try something like this:
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 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
[email protected]
[email protected]
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
|