Results 1 to 4 of 4

Thread: Selecting multiple entries in a List

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    130

    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)

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,458

    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

  3. #3
    Addicted Member ISAWHIM's Avatar
    Join Date
    Jan 2023
    Posts
    181

    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.
    Please, chime-in on my latest WIP.
    I can use all the help I can get.
    [VB6 Game], (In Development), "Galactic-Bondsman"

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    130

    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
  •  



Click Here to Expand Forum to Full Width