Problem solve Get help with specific problems with your technologies, process and projects.

Unchecking items in a CheckedListBox

How do I uncheck items in a CheckedListBox?
Private Sub Form1_Load(ByVal sender As System.Object, _
                       ByVal e As System.EventArgs) _
                       Handles MyBase.Load
    CheckedListBox1.Items.Add("First", True)
    CheckedListBox1.Items.Add("Second", True)
    CheckedListBox1.Items.Add("Third", True)
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, _
                          ByVal e As System.EventArgs) _
                          Handles Button3.Click
    ' Get the selected item index.
    Dim sel As Integer = CheckedListBox1.SelectedIndex
    If (sel <> -1) Then
        ' Get the selected item's check state.
        Dim chkstate As CheckState
        chkstate = CheckedListBox1.GetItemCheckState(sel)
        ' Toggle the item state.
        If (chkstate = CheckState.Checked) Then
            chkstate = CheckState.Unchecked
            chkstate = CheckState.Checked
        End If
        ' Set the new state.
        CheckedListBox1.SetItemCheckState(sel, chkstate)
    End If
End Sub

This was last published in December 2003

Dig Deeper on Win Development Resources

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.