PDA

View Full Version : visual basic checkboxlist max



mikenam
10-02-2007, 11:32 PM
Well trying to write a program where there is a checkboxlist and the maximum that should be allowed to check is 5.

this is what i have and its not working. i can select 9 and the max 5 literal will not display

For i = 0 To 9
If checkboxlist1.Items(i).Selected Then
count = count + 1
End If
Next
If count > 5 Then
Literal1.Text = "Maximum 5 cities"
End If


Thank You

MDK
10-14-2007, 08:22 PM
Well trying to write a program where there is a checkboxlist and the maximum that should be allowed to check is 5.

this is what i have and its not working. i can select 9 and the max 5 literal will not display

For i = 0 To 9
If checkboxlist1.Items(i).Selected Then
count = count + 1
End If
Next
If count > 5 Then
Literal1.Text = "Maximum 5 cities"
End If


Thank You

It's been a while since I did VB and I don't have it installed at the moment but I believe the property you are looking for is "checked" not "selected".(If there is any error that's where it is, the rest of the code seems fine). Selected is for when an item is highlighted.

Press . and look at the code hint window that pop up. you should be able to find the right property there.