CheckedListBox.CheckedItemCollection CheckedListBox.CheckedItemCollection CheckedListBox.CheckedItemCollection CheckedListBox.CheckedItemCollection Class

定义

封装 CheckedListBox 控件中选中项(包括处于不确定状态的项)的集合。Encapsulates the collection of checked items, including items in an indeterminate state, in a CheckedListBox control.

public: ref class CheckedListBox::CheckedItemCollection : System::Collections::IList
public class CheckedListBox.CheckedItemCollection : System.Collections.IList
type CheckedListBox.CheckedItemCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
Public Class CheckedListBox.CheckedItemCollection
Implements IList
继承
CheckedListBox.CheckedItemCollectionCheckedListBox.CheckedItemCollectionCheckedListBox.CheckedItemCollectionCheckedListBox.CheckedItemCollection
实现

示例

下面的示例枚举中的选中的项CheckedListBox.CheckedIndexCollection若要查看内容检查状态项中。The following example enumerates the checked items in the CheckedListBox.CheckedIndexCollection to see what check state an item is in. 该示例演示了如何使用GetItemCheckState方法设置项的复选状态。The example demonstrates using the GetItemCheckState method to set the check state of an item. 该示例还演示了如何使用CheckedIndices属性来获取CheckedListBox.CheckedIndexCollection,并CheckedItems属性来获取CheckedListBox.CheckedItemCollectionThe example also demonstrates using the CheckedIndices property to get the CheckedListBox.CheckedIndexCollection, and the CheckedItems property to get the CheckedListBox.CheckedItemCollection.

使用第一个循环GetItemCheckState方法以获取CheckState的每个选中的项,根据给定的项的索引。The first loop uses the GetItemCheckState method to get the CheckState of each checked item, given the index of the item. 第二个循环也使用GetItemCheckState,但使用ListBox.ObjectCollection.IndexOf方法来检索项的索引。The second loop also uses GetItemCheckState, but uses the ListBox.ObjectCollection.IndexOf method to retrieve the index for the item.

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控件; 它只包含这些项处于选中或不确定状态。The checked items collection is a subset of all items in the CheckedListBox control; it contains only those items that are in a checked or indeterminate state.

下表是控件 (包含在控件中的所有项) 中的项的索引集合的示例。The following table is an example of the indexed collection of items in the control (all items contained in the control).

索引Index Item 检查状态Check State
00 对象 1object 1 Unchecked
11 对象 2object 2 Checked
22 对象 3object 3 Unchecked
33 对象 4object 4 Indeterminate
44 对象 5object 5 Checked

根据前面的示例下, 表显示了选中项的索引的集合。Based on the previous example, the following table shows the indexed collection of the checked items.

索引Index Item
00 对象 2object 2
11 对象 4object 4
22 对象 5object 5

CheckedListBox类具有两个成员,可用于访问存储的索引Item[Int32]属性和IndexOf方法。The CheckedListBox class has two members that allow you to access the stored indexes, the Item[Int32] property and the IndexOf method.

基于前面的示例中,调用Item[Int32]参数值为 1 的属性返回 4 的对象。Based on the previous example, a call to the Item[Int32] property with a parameter value of 1 returns object 4. 调用IndexOf对象的参数 4 返回的值为 1。A call to IndexOf with a parameter of object 4 returns a value of 1.

属性

Count Count Count Count

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

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

获取指示该集合是否为只读的值。Gets a value indicating if the collection is read-only.

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

获取选中项集合中的一个对象。Gets an object in the checked items collection.

方法

Contains(Object) Contains(Object) Contains(Object) Contains(Object)

确定指定项是否位于集合内。Determines whether the specified item is located in the collection.

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32)

将整个集合复制到现有数组中,从该数组内的指定位置开始复制。Copies the entire collection into an existing array at a specified location within the array.

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()

返回一个可用于循环访问 CheckedItems 集合的枚举数。Returns an enumerator that can be used to iterate through the CheckedItems collection.

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 an index into the collection of checked items.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

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

ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

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

IList.Add(Object) IList.Add(Object) IList.Add(Object) IList.Add(Object)

有关此成员的说明,请参见 Add(Object)For a description of this member, see Add(Object).

IList.Clear() IList.Clear() IList.Clear() IList.Clear()

有关此成员的说明,请参见 Clear()For a description of this member, see Clear().

IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object)

有关此成员的说明,请参见 Insert(Int32, Object)For a description of this member, see Insert(Int32, Object).

IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize

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

IList.Remove(Object) IList.Remove(Object) IList.Remove(Object) IList.Remove(Object)

有关此成员的说明,请参见 Remove(Object)For a description of this member, see Remove(Object).

IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32)

有关此成员的说明,请参见 RemoveAt(Int32)For a description of this member, see RemoveAt(Int32).

扩展方法

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)

将转换IEnumerableIQueryableConverts an IEnumerable to an IQueryable.

适用于