|
-
Jul 3rd, 2009, 06:12 PM
#1
Thread Starter
New Member
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.
-
Jul 3rd, 2009, 06:20 PM
#2
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 3rd, 2009, 06:40 PM
#3
Thread Starter
New Member
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.
-
Jul 3rd, 2009, 06:44 PM
#4
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.
-
Jul 3rd, 2009, 07:28 PM
#5
Thread Starter
New Member
Re: Removing All Checked Items
Oh, now I see, that makes sense.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|