CheckedListBox.CheckedIndexCollection 类     
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
封装 CheckedListBox 中选中的项(包括处于不确定状态的项)的索引集合。
public: ref class CheckedListBox::CheckedIndexCollection : System::Collections::IList
	public class CheckedListBox.CheckedIndexCollection : System.Collections.IList
	type CheckedListBox.CheckedIndexCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
	Public Class CheckedListBox.CheckedIndexCollection
Implements IList
		- 继承
 - 
				CheckedListBox.CheckedIndexCollection
 
- 实现
 
示例
以下示例枚举选中的项 CheckedListBox.CheckedIndexCollection ,以查看项处于哪个检查状态。 该示例演示如何使用 GetItemCheckState 该方法设置项的检查状态。 该示例还演示了如何使用 CheckedIndices 属性来获取 CheckedListBox.CheckedIndexCollection,以及 CheckedItems 用于获取的属性 CheckedListBox.CheckedItemCollection。
第一个循环使用 GetItemCheckState 该方法获取 CheckState 每个已检查项(给定项的索引)。 第二个循环也使用 GetItemCheckState,但使用该 ListBox.ObjectCollection.IndexOf 方法检索项的索引。
void WhatIsChecked_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   
   // Display in a message box all the items that are checked.
   // First show the index and check state of all selected items.
   IEnumerator^ myEnum1 = checkedListBox1->CheckedIndices->GetEnumerator();
   while ( myEnum1->MoveNext() )
   {
      Int32 indexChecked =  *safe_cast<Int32^>(myEnum1->Current);
      
      // The indexChecked variable contains the index of the item.
      MessageBox::Show( String::Concat( "Index#: ", indexChecked, ", is checked. Checked state is: ", checkedListBox1->GetItemCheckState( indexChecked ), "." ) );
   }
   
   // Next show the Object* title and check state for each item selected.
   IEnumerator^ myEnum2 = checkedListBox1->CheckedItems->GetEnumerator();
   while ( myEnum2->MoveNext() )
   {
      Object^ itemChecked = safe_cast<Object^>(myEnum2->Current);
      
      // Use the IndexOf method to get the index of an item.
      MessageBox::Show( String::Concat( "Item with title: \"", itemChecked, "\", is checked. Checked state is: ", checkedListBox1->GetItemCheckState( checkedListBox1->Items->IndexOf( itemChecked ) ), "." ) );
   }
}
private void WhatIsChecked_Click(object sender, System.EventArgs e) {
    // Display in a message box all the items that are checked.
    // First show the index and check state of all selected items.
    foreach(int indexChecked in checkedListBox1.CheckedIndices) {
        // The indexChecked variable contains the index of the item.
        MessageBox.Show("Index#: " + indexChecked.ToString() + ", is checked. Checked state is:" +
                        checkedListBox1.GetItemCheckState(indexChecked).ToString() + ".");
    }
    // Next show the object title and check state for each item selected.
    foreach(object itemChecked in checkedListBox1.CheckedItems) {
        // Use the IndexOf method to get the index of an item.
        MessageBox.Show("Item with title: \"" + itemChecked.ToString() +
                        "\", is checked. Checked state is: " +
                        checkedListBox1.GetItemCheckState(checkedListBox1.Items.IndexOf(itemChecked)).ToString() + ".");
    }
}
Private Sub WhatIsChecked_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WhatIsChecked.Click
    ' Display in a message box all the items that are checked.
    Dim indexChecked As Integer
    Dim itemChecked As Object
    Const quote As String = """"
    ' First show the index and check state of all selected items.
    For Each indexChecked In CheckedListBox1.CheckedIndices
        ' The indexChecked variable contains the index of the item.
        MessageBox.Show("Index#: " + indexChecked.ToString() + ", is checked. Checked state is:" + _
                        CheckedListBox1.GetItemCheckState(indexChecked).ToString() + ".")
    Next
    ' Next show the object title and check state for each item selected.
    For Each itemChecked In CheckedListBox1.CheckedItems
        ' Use the IndexOf method to get the index of an item.
        MessageBox.Show("Item with title: " + quote + itemChecked.ToString() + quote + _
                        ", is checked. Checked state is: " + _
                        CheckedListBox1.GetItemCheckState(CheckedListBox1.Items.IndexOf(itemChecked)).ToString() + ".")
    Next
End Sub
	注解
选中的索引集合是控件中所有项的集合中的 CheckedListBox 索引子集。 这些索引指定处于选中状态或不确定状态的项。
下表是控件中项的索引集合的示例, (控件中包含的所有项) 。
| 索引 | Item | 检查状态 | 
|---|---|---|
| 0 | 对象 1 | Unchecked | 
| 1 | 对象 2 | Checked | 
| 2 | 对象 3 | Unchecked | 
| 3 | 对象 4 | Indeterminate | 
| 4 | 对象 5 | Checked | 
根据前面的示例,下表显示了已检查项索引的索引集合。
| 索引 | 项索引 | 
|---|---|
| 0 | 1 | 
| 1 | 3 | 
| 2 | 4 | 
该 CheckedListBox 类具有两个成员,可用于访问存储的索引、 Item[] 属性和 IndexOf 方法。
根据前面的示例,对 Item[] 参数值为 1 的属性的调用返回值 3。 使用参数 3 调用 IndexOf 将返回值 1。
属性
| Count |  
		 获取选中项数。  | 
        	
| IsReadOnly |  
		 获取一个值,该值指示集合是否为只读。  | 
        	
| Item[Int32] |  
		 获取 CheckedListBox 控件中某选中项的索引。  | 
        	
方法
| Contains(Int32) |  
		 确定指定索引是否位于集合中。  | 
        	
| CopyTo(Array, Int32) |  
		 将整个集合复制到现有数组中,从该数组内的指定位置开始复制。  | 
        	
| Equals(Object) | 
		   确定指定对象是否等于当前对象。 (继承自 Object) | 
        	
| GetEnumerator() |  
		 返回一个可用于循环访问 CheckedIndices 集合的枚举数。  | 
        	
| GetHashCode() | 
		   作为默认哈希函数。 (继承自 Object) | 
        	
| GetType() | 
		   获取当前实例的 Type。 (继承自 Object) | 
        	
| IndexOf(Int32) |  
		 返回选中索引集合中的一个索引。  | 
        	
| MemberwiseClone() | 
		   创建当前 Object 的浅表副本。 (继承自 Object) | 
        	
| ToString() | 
		   返回表示当前对象的字符串。 (继承自 Object) | 
        	
显式接口实现
| ICollection.IsSynchronized |  
		 获取一个值,该值指示是否同步对 CheckedListBox.CheckedIndexCollection 的访问(线程安全)。  | 
        	
| ICollection.SyncRoot |  
		 获取可用于同步控件集合访问的对象。 有关此成员的说明,请参见 SyncRoot。  | 
        	
| IList.Add(Object) |  
			 此 API 支持产品基础结构,不能在代码中直接使用。 将某项添加到 CheckedListBox.CheckedIndexCollection 中。 有关此成员的说明,请参见 Add(Object)。  | 
        	
| IList.Clear() |  
		 从 CheckedListBox.CheckedIndexCollection 中移除所有项。 有关此成员的说明,请参见 Clear()。  | 
        	
| IList.Contains(Object) |  
		 确定指定索引是否位于 CheckedListBox.CheckedIndexCollection 内。 有关此成员的说明,请参见 Contains(Object)。  | 
        	
| IList.IndexOf(Object) |  
		 有关此成员的说明,请参见 IndexOf(Object)。  | 
        	
| IList.Insert(Int32, Object) |  
		 有关此成员的说明,请参见 Insert(Int32, Object)。  | 
        	
| IList.IsFixedSize |  
		 有关此成员的说明,请参见 IsFixedSize。  | 
        	
| IList.Item[Int32] |  
		 有关此成员的说明,请参见 Item[Int32]。  | 
        	
| IList.Remove(Object) |  
		 有关此成员的说明,请参见 Remove(Object)。  | 
        	
| IList.RemoveAt(Int32) |  
		 或者此成员的说明(请参见 RemoveAt(Int32))。  | 
        	
扩展方法
| Cast<TResult>(IEnumerable) |  
		 将 IEnumerable 的元素强制转换为指定的类型。  | 
        	
| OfType<TResult>(IEnumerable) |  
		 根据指定类型筛选 IEnumerable 的元素。  | 
        	
| AsParallel(IEnumerable) |  
		 启用查询的并行化。  | 
        	
| AsQueryable(IEnumerable) |  
		 将 IEnumerable 转换为 IQueryable。  |