Removing All Checked Items
Hello, I have a slight problem. I'm trying to remove all the checked items in my CheckedListBox.
I started by doing CheckedListBox1.Items.Remove(CheckedListbox1.CheckedItems). That seemed like it would work, but it didn't. I soon discovered that CheckedListBox1.Items.Remove only works on the the strings of the individual items.
Is there a way to accomplish what I am trying to do?
Thanks for the help.
Re: Removing All Checked Items
try this:
vb Code:
For x As Integer = CheckedListBox1.Items.Count - 1 To 0 Step -1
If CheckedListBox1.CheckedIndices.Contains(x) Then CheckedListBox1.Items.RemoveAt(x)
Next
Re: Removing All Checked Items
It worked very nicely, thank you.
Quick question: I don't quite understand the "To 0 Step -1" part of the code, I would think that the Items.Count part would return a positive number.
Thanks.
Re: Removing All Checked Items
Instead of incrementing the counter (x) by one he is decreasing it by 1. So if you have 10 items in your CheckedListBox, it basically translates into: Starting from 9 go to 0 decreasing by 1 each time.
Re: Removing All Checked Items
Oh, now I see, that makes sense. :)