Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

How can I select/unselect all items of a CheckedListBox ONLY VIA FOR EACH?

This won't work for me:

For Each Chk As CheckBox In FieldsCheckedListBox.Items
   Chk.Checked = True
Next

Thanks.

  • Leaders
Posted

I don't think that this can generally be done via a for each loop. Unless you create your own class that references the CheckedListBox and can track/update its own checked status, and then populate the CheckedListBox with these, this can't be done.

 

The problem is that a for each loop iterates through the items that you've added. Typically this is some sort of simple value like a simple string or integer, which, of course, don't expose the functionality to examine their status in any list-type control that may contain them. With the for each loop you are using, what you are asking for is impossible. Do you have a compelling reason to prefer a for each loop over a for next loop?

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...