none
Unchecking CheckedListBox checkboxes in vb.net code

    Question

  • This shouldn't be too difficult. I'm trying to find a method that will allow me to uncheck (a Collection) of Checkboxes in a ListView control in Vb.Net code.

     

    I tried the method .Items.Clear but it removes the checkboxes completely from the WinForm. The .ClearSelected only removes what you've highlighted (or the item you've highlighted) from the GUI, not the checkbox. I've tried .SelectedItems, .CheckedItems, etc and I just can't find what I'm looking for. Any help would be welcomed!

     

    Thank you,

    Wallace

    Friday, July 20, 2007 8:41 PM

Answers

  • Here is an example from the help files-

     

                Dim myEnumerator As IEnumerator
                myEnumerator = checkedListBox1.CheckedIndices.GetEnumerator()
                Dim y As Integer
                While myEnumerator.MoveNext() <> False
                    y = CInt(myEnumerator.Current)
                    checkedListBox1.SetItemChecked(y, False)
                End While

     

     

    Saturday, July 21, 2007 2:18 PM

All replies

  •     For Each item As ListViewItem In ListView1.Items
          item.Checked = False
        Next

    Friday, July 20, 2007 10:01 PM
    Moderator
  • This just removes the highlighting from the last item checked in the CheckedListBox but it doesn't remove the check mark.

    Does it sound like another Sub need to be written within the Sub as a Click.Event and how would one write a sub under another sub? I've never done it.

     

    Thank you,

    Wallace

    Friday, July 20, 2007 10:53 PM
  • Here is an example from the help files-

     

                Dim myEnumerator As IEnumerator
                myEnumerator = checkedListBox1.CheckedIndices.GetEnumerator()
                Dim y As Integer
                While myEnumerator.MoveNext() <> False
                    y = CInt(myEnumerator.Current)
                    checkedListBox1.SetItemChecked(y, False)
                End While

     

     

    Saturday, July 21, 2007 2:18 PM
  • Hi nbk5533

     

    Use ListViewItem.Checked property. Hope may helps.

     

    Regards

    Wei Zhou

    Monday, July 23, 2007 8:00 AM
  • Thank you to everyone for your input. To cwillsh, nice job. This is just the solution I needed and it worked perfectly.

     

    Wallace

    Monday, July 23, 2007 3:09 PM
  • I needed to do this same thing and was able to use this code. It works but I don't understand why. Can someone explain it please? I tried code suggested elsewhere in these forums for doing this. ie:

    for each item in checkedlistbox1.checkeditems
              checkedlistbox1.setitemcheckstate(checkedlistbox1.items.indexof(item), checkstate.unchecked)
    next

    This looks like it should work but I get the following error when I try to implement it:

    "List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change."

    My checkboxes are designed to have only 2 selections. I assume that this error means that once I change the checkstate of the first of the two items, my next statement cannot be used. Any thoughts on a simple fix to this?

    Thanks.
    Friday, July 31, 2009 3:30 AM
  • Thanks cwillsh, this works perfectly.
    Sunday, September 30, 2012 5:37 PM