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

后端 未结 2 1030
北恋
北恋 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.

    0 讨论(0)
  • 2021-01-02 09:57
    For Each item In SuppliersCheckList.CheckedItems
            If SuppliersCheckList.GetItemCheckState(SuppliersCheckList.Items.IndexOf(item)) Then
                MsgBox(item.ToString)
            End If
    Next
    
    0 讨论(0)
提交回复
热议问题