|
-
Oct 11th, 2002, 06:49 AM
#1
Thread Starter
Lively Member
Listbox / Multiselect / Alphabetical select
When I Press any key on my keyboard...I want to have the item highlighted which is as near as possible...
"A" should result in the first item which start with A...after "A" I press...."B" and I get some item which starts with AB selected...
I found some code which works fine when you have a normal listbox..when I use a MultiSelect box it doesn't work anymore...with a normal box it works perfect
VB Code:
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
Const LB_FINDSTRING = &H18F
Private Sub Text1_Change()
'Retrieve the item's listindex
List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))
End Sub
-
Oct 11th, 2002, 07:11 AM
#2
Im not completly sure what you are asking. If what you want it something like the Index area of a help file, then use this in a sorted ListBox.
Function ListSearch(KeyField) As Integer
Dim Lower As Integer, Upper As Integer, Middle As Integer
Dim MiddleItem As String
Lower = 0
Upper = List1.ListCount - 1
While 1
Middle = Fix((Lower + Upper) / 2)
MiddleItem = List1.List(Middle)
If Upper < Lower Then
ListSearch = -1
Exit Function
End If
If StrComp(KeyField, Left(MiddleItem, Len(KeyField))) > 0 Then
Lower = Middle + 1
Else
If StrComp(KeyField, Left(MiddleItem, Len(KeyField))) < 0 Then
Upper = Middle - 1
Else
ListSearch = Middle
Exit Function
End If
End If
Wend
End Function
Then add a TextBox to your form, make its Visible property to false, then type this
Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)
Text1.Text = Text1.Text + Chr(KeyCode)
End Sub
Private Sub Text1_Change()
Dim pos As Integer
pos = ListSearch(Trim$(Text1.Text))
If pos >= 0 Then
List1.ListIndex = pos
Else
End If
End Sub
Make sure that code is in a SORTED list box. It searches alphabetically. If what you mean is something like it selects 2 things at a time with say;
(Selected)Apple
(Selected)Above
(Selected)Across
(Not Selected)Zebra
then the above code will not work. I doubt you will find any code if that is what you mean. But, good luck....
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Oct 11th, 2002, 07:54 AM
#3
Thread Starter
Lively Member
Nope...
I mean it just have to do same as the code I just gave...but it should also work with Multiselect boxes....
It doesn't have to Multiselect items...
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
|