CodeItBetter Programming Another VB Programming Blog

How to Link a text box to a list box? So, as you type, it highlights any matching entries

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'Controls - How to Link a text box to a list box? So, as you type, it highlights any matching entries
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 LB_FINDSTRING = &H18F
 
Private Sub Text1_Change()
    List1.ListIndex = SendMessage(List1.hWnd, LB_FINDSTRING, -1, ByVal Text1.Text)
    List1.Visible = (List1.ListIndex >= 0)
End Sub
 
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 9 Then
        Text1.Text = List1.List(List1.ListIndex)
        Text1.SelStart = Len(Text1)
        KeyCode = 0
    End If
End Sub
 
Private Sub Text1_LostFocus()
    If (List1.ListIndex >= 0) Then
        Text1.Text = List1.List(List1.ListIndex)
        Text1.SelStart = Len(Text1)
    End If
End Sub
Filed under: Controls Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.