February 6th, 2003, 02:18 AM
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?
February 6th, 2003, 02:41 AM
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"
February 6th, 2003, 04:59 AM
Thanks. The code serve the purpose.
But, is there any way to set Multiselect at runtime?
February 6th, 2003, 02:36 PM
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.
Your code can only be as good as your algorithm.
Click Here to Expand Forum to Full Width