Friday, July 20, 2007 8:41 PM
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!
Friday, July 20, 2007 10:01 PMModeratorFor Each item As ListViewItem In ListView1.Items
item.Checked = False
Friday, July 20, 2007 10:53 PM
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.
Saturday, July 21, 2007 2:18 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)
Monday, July 23, 2007 8:00 AM
Use ListViewItem.Checked property. Hope may helps.
Monday, July 23, 2007 3:09 PM
Thank you to everyone for your input. To cwillsh, nice job. This is just the solution I needed and it worked perfectly.
Friday, July 31, 2009 3:30 AMI 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
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?
Sunday, September 30, 2012 5:37 PMThanks cwillsh, this works perfectly.