Checklistbox - clear item

How can I clear all selected items in Checklistbox? I am using VS2005.


    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

        For Each item As ListItem In Me.CheckBoxList1.Items

            If item.Selected Then

                Response.Write(item.ToString & " ")


            End If



        Next

        Me.CheckBoxList1.SelectedItem = -1  ???? error


 
    End Sub
VBdotnet2005Asked:
Who is Participating?
 
j-w-thomasConnect With a Mentor Commented:
Sorry correct that, it should be "...Items(i)..."

Me.CheckBoxList.Items(i).Selected = false
0
 
j-w-thomasCommented:
You have to use a loop to clear each one individually.


for i = 0 to Me.CheckBoxList.Items.Count - 1
     
     Me.CheckBoxList.Item(i).Selected = false

next

John
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.