-
Mar 1st, 2024, 07:15 PM
#1
Thread Starter
Addicted Member
Selecting multiple entries in a List
Code:
Private Sub Search_Click()
Dim MacroSearchArray() As String
Dim i As Integer
Dim A As Integer
MacroSearchArray = Init_Macros.fSearchMacroByName(Temp_SearchMacroByName)
For i = LBound(MacroSearchArray) To UBound(MacroSearchArray)
If i >= 0 Then
If Len(MacroSearchArray(i)) > 0 Then
Debug.Print MacroSearchArray(i)
A = Val(MacroSearchArray(i))
FunctionList.Selected(A) = True
End If
End If
Next
End Sub
MacroSearchArray consists of numerics in string format (1 to 1005 possible)
FunctionList is a scrollable doubleclick list
A search term is entered into another Sub which is then passed to Function fSearchMacroByName which returns to populate array MacroSearchArray in Sub Search with any items in FunctionList that match the search term.
What I want to do is highlight all entries in FunctionList that match the search term. The problem I'm running into is the only item selected in FunctionList is the next entry AFTER the last match to the search term. I obviously want ALL matches in the list to be Selected (although I am really only interested in highlighting them)
-
Mar 1st, 2024, 07:31 PM
#2
Re: Selecting multiple entries in a List
Make sure MultiSelect property of the ListBox is 1 or 2.
Your posted code seems to contain some convoluted logic as I read it, but I suspect your code would work if you changed the last functional line to this:
Code:
FunctionList.Selected(i) = True
-
Mar 2nd, 2024, 09:18 AM
#3
Addicted Member
Re: Selecting multiple entries in a List
May also want to add an ELSE...
FunctionList.Selected(i) = False
So it unselects things that were previously selected the first time, on a new pass.
-
Mar 2nd, 2024, 01:39 PM
#4
Thread Starter
Addicted Member
Re: Selecting multiple entries in a List
Thanks all. This is what I ended up with and it works fine (also, after setting Multiselect to 1)
Code:
Private Sub Search_Click()
Dim MacroSearchArray() As String
Dim i As Integer
MacroSearchArray = Init_Macros.fSearchMacroByName(Temp_SearchMacroByName)
For i = LBound(MacroSearchArray) To UBound(MacroSearchArray)
If i >= 0 Then
If Len(MacroSearchArray(i)) > 0 Then
FunctionList.Selected(i - 1) = True
Else
FunctionList.Selected(i - 1) = False
End If
End If
Next
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
|