Select and Deselect multiple times in a listbox

MobiusDick

Hippy Materialist
Local time
Today, 06:03
Joined
Aug 23, 2007
Messages
23
Hi All,

I have a form with a listbox. Underneath this listbox I have a command button that selects and deselects all of the values in that list box, however, I can't seem to make it a continuos loop.

i.e. I can select the data and then deselect the data- but only once.

Does anyone have any ideas how I could change the following code to select and deselect the values in the listbox as many times as I want.

I have tried various loops and things-most of which end up in a self-perpetuating cycle.

As ever, any and all suggestions appreciated.

Code:
Dim intListCount As Integer
    
    If btnHHMPANSelector.Caption = "Select All" Then
    
        For intListCount = 0 To lstHHMPAN.ListCount
            lstHHMPAN.Selected(intListCount) = True
        Next intListCount
        btnHHMPANSelector.Caption = "Deselect All"
        
    Else
    
        For intListCount = 0 To lstHHMPAN.ListCount
            lstHHMPAN.Selected(intListCount) = False
        Next intListCount
        btnHHMPANSelector.Caption = "Deselect All"
        
    End If
 
Try:
Code:
Dim intListCount As Integer

If btnHHMPANSelector.Caption = "Select All" Then

   For intListCount = 0 To lstHHMPAN.ListCount
      lstHHMPAN.Selected(intListCount) = True
   Next intListCount
   btnHHMPANSelector.Caption = "Deselect All"

Else

   For intListCount = 0 To lstHHMPAN.ListCount
      lstHHMPAN.Selected(intListCount) = False
   Next intListCount
   btnHHMPANSelector.Caption = "[COLOR="Red"][B]Select All[/B][/COLOR]"

End If
 
Hi RuralGuy,

Thank you very much- does exactly what I wanted now- such a simple change too!! :)
 

Users who are viewing this thread

Back
Top Bottom