Hi again,
I have a list box which display the following:
0001 - First Game
0002 - Second Game
0004 - Thrid Game 'Sometimes theres one missing eg 0002 - 0004
What i am trying to do is a search so that the user can type 0 into a box named str_search and then click search and it will jump to the list with a 0 in it, how would i go about doing this.
Also because there is three 0 in the first three, i only want it to jump to each item in the list once.
Option Explicit
Private Declare Function SendMessageByNum Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, ByVal _
wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const LB_SETHORIZONTALEXTENT = &H194
Private Sub Form_Load()
List1.AddItem "this is a test. this is only a test."
SendMessageByNum List1.hwnd, LB_SETHORIZONTALEXTENT, 250, 0
End Sub
Sub lstAddHScroll(lst As ListBox)
Dim a%, m%
' depends on the scalewidth
' if scalemode is Twips then Divide M by 15 to get Pixels
For a = 0 To lst.ListCount - 1
If Me.TextWidth(lst.List(a)) > m Then m = Me.TextWidth(lst.List(a))
Next
SendMessageByNum lst.hwnd, LB_SETHORIZONTALEXTENT, m / 15, 0
End Sub
Hi again,
I have a list box which display the following:
0001 - First Game
0002 - Second Game
0004 - Thrid Game 'Sometimes theres one missing eg 0002 - 0004
What i am trying to do is a search so that the user can type 0 into a box named str_search and then click search and it will jump to the list with a 0 in it, how would i go about doing this.
Also because there is three 0 in the first three, i only want it to jump to each item in the list once.
Thanks
Chris
IMHO, you'd save yourself a lot of trouble by searching for the precence of "1" or "2" or "4" etc. in the list - that would ensure that you get only one result at a time, instead of adding more logic to compensate for the 3 zero's
I assume you want to jump to the first matching item. So if you type in more letters the more precise will be your jump.
In the below sample the ListView is call lstSoundFiles. (I just took it from another sample I did recently).
You type letters in a TextBox named txt_search, click on a button named btnSearch and the jump will take place.
Code:
Private Sub btnSearch_Click()
Dim i%
For i = 0 To lstSoundFiles.ListCount - 1
If InStr(lstSoundFiles.List(i), txt_search.Text) = 1 Then
lstSoundFiles.ListIndex = i
Exit Sub
End If
Next
MsgBox "notfound", vbOKOnly
End Sub
Bookmarks