For each in CheckedListBox. returns as Object and not as Control

后端 未结 2 1032
北恋
北恋 2021-01-02 09:27

I have a CheckedListBox previously populated. I want to loop with a \"for each / next\" through all items in the CheckedListBox and do a lot of \"stuff\" with each iteration

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-02 09:41

    A CheckedListBox is not a collection of CheckBox controls.
    It does not have a collection of wrapper objects.

    The CheckedListBox control is a simple control that can only display a plain list of items; it sounds like you're looking for something more powerful. (For example, it is impossible to change the background color of an individual item without owner-drawing)

    You should use a ListView (with the CheckBoxes property set to true) instead.
    You can then loop through the ListViewItem instances in its Items collection.

提交回复
热议问题