-
I have a checked listbox. I would like to initialise all options to be checked initially. I tried to put the following in the form Load:
For i = 0 To lstChoices.ListIndex - 1
lstChoices.Selected(i) = True
Next i
But the above does not display checks on my screen. How do I display a checkbox with all list entries checked when initialise the form?
-
Try this:
Code:
Private Sub Form_Load()
With List1
For i = .ListCount - 1 To 0 Step -1
.Selected(i) = True
Next
End With
End Sub
-
Thanks, Matthew!
It worked perfectly!
I would like to understand why mine did not work and yours did? I can see you went backwards with i, does this matter?
Many thanks,
Sandra
-
For i = 0 To lstChoices.ListIndex - 1
lstChoices.Selected(i) = True
Next i
You have ListIndex. This is the reason it does not work because it's not actually counting anything on the List.
It does not matter whether you go backwards or not.
This will work as well:
Code:
For i = 0 To List1.ListCount - 1
List1.Selected(i) = True
Next i
-
Yes, got it. Listindex was a typo, I meant ListCount. "Looking at it and not seeing it" was my sindrome.
Thanks!