CheckedListBox.ObjectCollection 类    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示 CheckedListBox 中项的集合。
public: ref class CheckedListBox::ObjectCollection : System::Windows::Forms::ListBox::ObjectCollectionpublic class CheckedListBox.ObjectCollection : System.Windows.Forms.ListBox.ObjectCollectiontype CheckedListBox.ObjectCollection = class
    inherit ListBox.ObjectCollectionPublic Class CheckedListBox.ObjectCollection
Inherits ListBox.ObjectCollection- 继承
示例
以下示例枚举 中的 CheckedListBox 项,并检查列表中的所有其他项。 该示例演示如何使用 Items 属性获取 CheckedListBox.ObjectCollection 来获取 Count 项的 。
该示例还演示如何使用 SetItemCheckState 和 SetItemChecked 方法来设置项的检查状态。 对于要检查的其他每个项, SetItemCheckState 调用 以将 设置为 CheckStateIndeterminate,而 SetItemChecked 对另一项调用 以将选中状态设置为 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 集合。 若要创建对象集合以显示在控件中CheckedListBox,可以使用 和 Remove 方法单独Add添加或删除项。
构造函数
| CheckedListBox.ObjectCollection(CheckedListBox) | 初始化 CheckedListBox.ObjectCollection 类的新实例。 | 
属性
| Count | 获取集合中的项数。(继承自 ListBox.ObjectCollection) | 
| IsReadOnly | 获取一个值,该值指示集合是否为只读。(继承自 ListBox.ObjectCollection) | 
| Item[Int32] | 获取或设置集合中指定索引处的项。(继承自 ListBox.ObjectCollection) | 
方法
显式接口实现
| ICollection.CopyTo(Array, Int32) | 此 API 支持产品基础结构,不能在代码中直接使用。 从特定的数组索引开始,将集合的元素复制到数组中。(继承自 ListBox.ObjectCollection) | 
| ICollection.IsSynchronized | 有关此成员的说明,请参见 IsSynchronized。(继承自 ListBox.ObjectCollection) | 
| ICollection.SyncRoot | 有关此成员的说明,请参见 SyncRoot。(继承自 ListBox.ObjectCollection) | 
| IList.Add(Object) | 此 API 支持产品基础结构,不能在代码中直接使用。 将对象添加到 ListBox 类中。(继承自 ListBox.ObjectCollection) | 
| IList.Contains(Object) | 确定 IList 是否包含特定值。(继承自 ListBox.ObjectCollection) | 
| IList.IndexOf(Object) | 确定 IList 中特定项的索引。(继承自 ListBox.ObjectCollection) | 
| IList.Insert(Int32, Object) | 在 IList 中的指定索引处插入一个项。(继承自 ListBox.ObjectCollection) | 
| IList.IsFixedSize | 有关此成员的说明,请参见 IsFixedSize。(继承自 ListBox.ObjectCollection) | 
| IList.Item[Int32] | 获取或设置指定索引处的元素。(继承自 ListBox.ObjectCollection) | 
| IList.Remove(Object) | 从 IList 中移除特定对象的第一个匹配项。(继承自 ListBox.ObjectCollection) | 
扩展方法
| Cast<TResult>(IEnumerable) | 将 IEnumerable 的元素强制转换为指定的类型。 | 
| OfType<TResult>(IEnumerable) | 根据指定类型筛选 IEnumerable 的元素。 | 
| AsParallel(IEnumerable) | 启用查询的并行化。 | 
| AsQueryable(IEnumerable) | 将 IEnumerable 转换为 IQueryable。 |