我有一个包含几千个项目的列表框。如果我想获得第一场比赛, @AngryHacker 在此威胁中给出的以下代码非常适合。但有时我有多个项目具有相同的数据。所以,我想得到所有的比赛,怎么做?
哦,实际上,它是这样的:aa4 sds aa5 aa6 fdf dsf
从列表中,我想获取以“aa”开头的项目的索引
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
'constants for searching the ListBox
Private Const LB_FINDSTRINGEXACT = &H1A2
Private Const LB_FINDSTRING = &H18F
'function to get find an item in the Listbox
Public Function GetListBoxIndex(hWnd As Long, SearchKey As String, Optional FindExactMatch As Boolean = True) As Long
If FindExactMatch Then
GetListBoxIndex = SendMessage(hWnd, LB_FINDSTRINGEXACT, -1, ByVal SearchKey)
Else
GetListBoxIndex = SendMessage(hWnd, LB_FINDSTRING, -1, ByVal SearchKey)
End If
End Function