CodeItBetter Programming Another VB Programming Blog

How to find list box item

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 find list box item
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const LB_FINDSTRING = &H18F
 
Private Sub cmdSearch_Click()
    Dim item_index As Long
 
    item_index = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ItemText.Text)
    If item_index < 0 Then
        MsgBox "Item not found"
    Else
        MsgBox "Item " & Format$(item_index)
    End If
End Sub
 
Private Sub Form_Load()
    List1.AddItem "ATT" & vbTab & "ATTENDANCE"
    List1.AddItem "ACT" & vbTab & "ACTIVITY"
    List1.AddItem "DEP" & vbTab & "DEPARTMENT"
    List1.AddItem "MTG" & vbTab & "MEETING"
    List1.AddItem "BRK" & vbTab & "BREAK"
    List1.AddItem "SIC" & vbTab & "SICK"
End Sub
Filed under: Controls Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.