-
Multiselect in Listbox
I am using listbox control with Multiselect option set to Simple. Is it possible to restrict the number of items selected by the user? For example, I want user to select 5 items & if he try to select more, he should get a message that maximum items are selected and it should not be possible for him to select any more items. Is it possible to set the multiselect property at runtime?
-
Try this with a form containing listbox named list1:
Private Sub List1_Click()
If Me.List1.SelCount > 5 Then
List1.Selected(List1.ListIndex) = False
MsgBox "No way man! you have selected 5 item"
End If
End Sub
-
Thanks. The code serve the purpose.
But, is there any way to set Multiselect at runtime?
-
No- At run time time that property is read only. But if you set it to Extended at design time you can modify its behaviour with the code you have and the _MouseDown Event to SIMULATE any other mode.