-
November 19th, 2008, 07:54 PM
#1
Searching List1
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
-
November 19th, 2008, 09:01 PM
#2
Re: Searching List1
Try this:
Code:
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
-
November 20th, 2008, 02:06 AM
#3
Re: Searching List1
Originally Posted by Chrispy360
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
-
November 20th, 2008, 02:54 AM
#4
Re: Searching List1
Could you elaborate more? All your data has zero so it will jump on all of them.
-
November 20th, 2008, 08:37 AM
#5
Re: Searching List1
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
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
|