Himanshu
Himanshu

Reputation: 32602

Limit selections in a listbox in vb6

How can I limit the selection of ListBox in VB6?
What I want: User can select maximum 8 Item from ListBox.

I am using this code:

Private Sub lstBox1_Click()
     If lstBox1.SelCount > 8 Then
        MsgBox "Maximum 8 items can be selected."             
       'I want here return false
     End if
End Sub

Upvotes: 3

Views: 1335

Answers (1)

Himanshu
Himanshu

Reputation: 32602

Here is the answer:

lstBox1.Selected(lstBox1.ListIndex) = False

Example:

Private Sub lstBox1_Click()
     If lstBox1.SelCount > 8 Then
        MsgBox "Maximum 8 items can be selected."             
       'I want here return false
        lstBox1.Selected(lstBox1.ListIndex) = False
     End if
End Sub

Upvotes: 5

Related Questions