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

定义

表示 CheckedListBox 中项的集合。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
继承
CheckedListBox.ObjectCollectionCheckedListBox.ObjectCollectionCheckedListBox.ObjectCollectionCheckedListBox.ObjectCollection

示例

下面的示例对中CheckedListBox的项进行枚举, 并检查列表中的所有其他项。The following example enumerates the items in the CheckedListBox and checks every other item in the list. 该示例演示如何使用Items属性CheckedListBox.ObjectCollection获取以获取Count项的。The example demonstrates using the Items property to get the CheckedListBox.ObjectCollection to get the Count of items.

该示例还演示了如何SetItemCheckState使用SetItemChecked和方法来设置项的复选状态。The example also demonstrates using the SetItemCheckState and SetItemChecked methods to set the check state of an item. 对于要检查的每个其他SetItemCheckState项, 将调用以CheckState将设置为Indeterminate, 而SetItemChecked在另一项上调用以将选中状态设置为CheckedFor 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

注解

从父控件CheckedListBox Items按属性访问集合。The collection is accessed from the parent control, CheckedListBox, by the Items property. 若要创建要在CheckedListBox控件中显示的对象的集合, 可以Add使用和Remove方法分别添加或移除项。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.

构造函数

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

初始化 CheckedListBox.ObjectCollection 类的新实例。Initializes a new instance of the CheckedListBox.ObjectCollection class.

方法

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

ListBox 的项列表添加项。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)

CheckedListBox 的项列表添加项,指定要添加的对象以及它是否选中。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)

CheckedListBox 的项列表添加项,指定要添加的对象以及初始选中值。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)

将现有 ListBox.ObjectCollection 的项添加到 ListBox 中项的列表中。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[])

ListBox 的项列表添加项的数组。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()

获取当前实例的 TypeGets 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()

创建当前 Object 的浅表副本。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)

属性

Count Count Count Count

获取集合中的项数。Gets the number of items in the collection.

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

有关此成员的说明,请参见 IsSynchronizedFor a description of this member, see IsSynchronized.

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

有关此成员的说明,请参见 SyncRootFor a description of this member, see SyncRoot.

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

有关此成员的说明,请参见 IsFixedSizeFor 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)

显式界面实现

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)

将对象添加到 ListBox 类中。Adds an object to the ListBox class.

(Inherited from ListBox.ObjectCollection)

扩展方法

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

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

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

根据指定类型筛选 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)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于