CheckedListBox

ADO DOT NET

Centurion
Joined
Dec 20, 2006
Messages
160
Hi,
How can I select/unselect all items of a CheckedListBox ONLY VIA FOR EACH?
This won't work for me:
Visual Basic:
For Each Chk As CheckBox In FieldsCheckedListBox.Items
    Chk.Checked = True
Next
Thanks.
 
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?
 
Back
Top