CheckedListBox.ObjectCollection CheckedListBox.ObjectCollection CheckedListBox.ObjectCollection CheckedListBox.ObjectCollection Class

Definition

Represents the collection of items in a CheckedListBox.

public: ref class CheckedListBox::ObjectCollection : System::Windows::Forms::ListBox::ObjectCollection
public class CheckedListBox.ObjectCollection : System.Windows.Forms.ListBox.ObjectCollection
type CheckedListBox.ObjectCollection = class
    inherit ListBox.ObjectCollection
Public Class CheckedListBox.ObjectCollection
Inherits ListBox.ObjectCollection
Inheritance
CheckedListBox.ObjectCollectionCheckedListBox.ObjectCollectionCheckedListBox.ObjectCollectionCheckedListBox.ObjectCollection

Examples

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.

void CheckEveryOther_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   
   // Cycle through every item and check every other.
   // Set flag to true to know when this code is being executed. Used in the ItemCheck
   // event handler.
   insideCheckEveryOther = true;
   for ( int i = 0; i < checkedListBox1->Items->Count; i++ )
   {
      
      // For every other item in the list, set as checked.
      if ( (i % 2) == 0 )
      {
         
         // But for each other item that is to be checked, set as being in an
         // indeterminate checked state.
         if ( (i % 4) == 0 )
                     checkedListBox1->SetItemCheckState( i, CheckState::Indeterminate );
         else
                     checkedListBox1->SetItemChecked( i, true );
      }

   }
   insideCheckEveryOther = false;
}


private void CheckEveryOther_Click(object sender, System.EventArgs e) {
    // Cycle through every item and check every other.

    // Set flag to true to know when this code is being executed. Used in the ItemCheck
    // event handler.
    insideCheckEveryOther = true;

    for (int i = 0; i < checkedListBox1.Items.Count; i++) {
        // For every other item in the list, set as checked.
        if ((i % 2) == 0) {
            // But for each other item that is to be checked, set as being in an
            // indeterminate checked state.
            if ((i % 4) == 0)
                checkedListBox1.SetItemCheckState(i, CheckState.Indeterminate);
            else
                checkedListBox1.SetItemChecked(i, true);
        }
    }        

    insideCheckEveryOther = false;
}
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

Remarks

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.

Constructors

CheckedListBox.ObjectCollection(CheckedListBox) CheckedListBox.ObjectCollection(CheckedListBox) CheckedListBox.ObjectCollection(CheckedListBox) CheckedListBox.ObjectCollection(CheckedListBox)

Initializes a new instance of the CheckedListBox.ObjectCollection class.

Methods

Add(Object) Add(Object) Add(Object) Add(Object)

Adds an item to the list of items for a ListBox.

(Inherited from ListBox.ObjectCollection)
Add(Object, Boolean) Add(Object, Boolean) Add(Object, Boolean) Add(Object, Boolean)

Adds an item to the list of items for a CheckedListBox, specifying the object to add and whether it is checked.

Add(Object, CheckState) Add(Object, CheckState) Add(Object, CheckState) Add(Object, CheckState)

Adds an item to the list of items for a CheckedListBox, specifying the object to add and the initial checked value.

AddRange(ListBox+ObjectCollection) AddRange(ListBox+ObjectCollection) AddRange(ListBox+ObjectCollection) AddRange(ListBox+ObjectCollection)

Adds the items of an existing ListBox.ObjectCollection to the list of items in a ListBox.

(Inherited from ListBox.ObjectCollection)
AddRange(Object[]) AddRange(Object[]) AddRange(Object[]) AddRange(Object[])

Adds an array of items to the list of items for a ListBox.

(Inherited from ListBox.ObjectCollection)
Clear() Clear() Clear() Clear()

Removes all items from the collection.

(Inherited from ListBox.ObjectCollection)
Contains(Object) Contains(Object) Contains(Object) Contains(Object)

Determines whether the specified item is located within the collection.

(Inherited from ListBox.ObjectCollection)
CopyTo(Object[], Int32) CopyTo(Object[], Int32) CopyTo(Object[], Int32) CopyTo(Object[], Int32)

Copies the entire collection into an existing array of objects at a specified location within the array.

(Inherited from ListBox.ObjectCollection)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Returns an enumerator to use to iterate through the item collection.

(Inherited from ListBox.ObjectCollection)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
IndexOf(Object) IndexOf(Object) IndexOf(Object) IndexOf(Object)

Returns the index within the collection of the specified item.

(Inherited from ListBox.ObjectCollection)
Insert(Int32, Object) Insert(Int32, Object) Insert(Int32, Object) Insert(Int32, Object)

Inserts an item into the list box at the specified index.

(Inherited from ListBox.ObjectCollection)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(Object) Remove(Object) Remove(Object) Remove(Object)

Removes the specified object from the collection.

(Inherited from ListBox.ObjectCollection)
RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

Removes the item at the specified index within the collection.

(Inherited from ListBox.ObjectCollection)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Properties

Count Count Count Count

Gets the number of items in the collection.

(Inherited from ListBox.ObjectCollection)
ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

For a description of this member, see IsSynchronized.

(Inherited from ListBox.ObjectCollection)
ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

For a description of this member, see SyncRoot.

(Inherited from ListBox.ObjectCollection)
IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize

For a description of this member, see IsFixedSize.

(Inherited from ListBox.ObjectCollection)
IsReadOnly IsReadOnly IsReadOnly IsReadOnly

Gets a value indicating whether the collection is read-only.

(Inherited from ListBox.ObjectCollection)
Item[Int32] Item[Int32] Item[Int32] Item[Int32]

Gets or sets the item at the specified index within the collection.

(Inherited from ListBox.ObjectCollection)

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

Copies the elements of the collection to an array, starting at a particular array index.

(Inherited from ListBox.ObjectCollection)
IList.Add(Object) IList.Add(Object) IList.Add(Object) IList.Add(Object)

Adds an object to the ListBox class.

(Inherited from ListBox.ObjectCollection)

Extension Methods

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to