CheckedListBox.ObjectCollection Class
Represents the collection of items in a CheckedListBox.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The collection is accessed from the parent control, CheckedListBox, by the Items property. To create a collection of objects to display in the CheckedListBox control, you can add or remove the items individually by using the Add and Remove methods.
The following example enumerates the items in the CheckedListBox and checks every other item in the list. The example demonstrates using the Items property to get the CheckedListBox.ObjectCollection to get the Count of items.
The example also demonstrates using the SetItemCheckState and SetItemChecked methods to set the check state of an item. For every other item that is to be checked, SetItemCheckState is called to set the CheckState to Indeterminate, while SetItemChecked is called on the other item to set the checked state to Checked.
Private Sub CheckEveryOther_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckEveryOther.Click ' Cycle through every item and check every other. Dim i As Integer ' Set flag to true to know when this code is being executed. Used in the ItemCheck ' event handler. insideCheckEveryOther = True For i = 0 To CheckedListBox1.Items.Count - 1 ' For every other item in the list, set as checked. If ((i Mod 2) = 0) Then ' But for each other item that is to be checked, set as being in an ' indeterminate checked state. If ((i Mod 4) = 0) Then CheckedListBox1.SetItemCheckState(i, CheckState.Indeterminate) Else CheckedListBox1.SetItemChecked(i, True) End If End If Next insideCheckEveryOther = False End Sub
System.Windows.Forms.ListBox.ObjectCollection
System.Windows.Forms.CheckedListBox.ObjectCollection
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.