CheckedListBox.CheckedIndexCollection CheckedListBox.CheckedIndexCollection CheckedListBox.CheckedIndexCollection CheckedListBox.CheckedIndexCollection Class

定義

封裝 CheckedListBox 中已選取項目 (包括不定狀態中的項目) 的索引集合。Encapsulates the collection of indexes of checked items (including items in an indeterminate state) in a 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.CheckedIndexCollectionCheckedListBox.CheckedIndexCollectionCheckedListBox.CheckedIndexCollectionCheckedListBox.CheckedIndexCollection
實作

範例

下列範例會列舉在選取的項目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 indexes collection is a subset of the indexes into the collection of all items in the CheckedListBox control. 這些索引會指定項目處於已核取或不定狀態。These indexes specify items 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 indexes of checked items.

索引Index 項目的索引Index of Item
00 11
11 33
22 44

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 的參數與傳回值為 3。Based on the previous example, a call to the Item[Int32] property with a parameter value of 1 returns a value of 3. 呼叫IndexOf3 的參數與傳回值為 1。A call to IndexOf with a parameter of 3 returns a value of 1.

屬性

Count Count Count Count

取得已選取項目的數目。Gets the number of checked items.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

取得值,表示集合是否為唯讀。Gets a value indicating whether the collection is read-only.

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

取得 CheckedListBox 控制項中已選取項目的索引。Gets the index of a checked item in the CheckedListBox control.

方法

Contains(Int32) Contains(Int32) Contains(Int32) Contains(Int32)

判斷指定的索引是否位於集合中。Determines whether the specified index 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()

傳回列舉值,可用來逐一查看 CheckedIndices 集合。Returns an enumerator that can be used to iterate through the CheckedIndices 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(Int32) IndexOf(Int32) IndexOf(Int32) IndexOf(Int32)

傳回已選取索引集合內的索引。Returns an index into the collection of checked indexes.

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

建立目前 Object 的淺層複本 (Shallow Copy)。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

取得值,這個值表示對 CheckedListBox.CheckedIndexCollection 的存取是否同步 (安全執行緒)。Gets a value indicating whether access to the CheckedListBox.CheckedIndexCollection is synchronized (thread safe).

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

取得可用來對控制項集合進行同步 (Synchronize) 存取的物件。Gets an object that can be used to synchronize access to the collection of controls. 如需這個成員的說明,請參閱 SyncRootFor a description of this member, see SyncRoot.

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

將項目加入至 CheckedListBox.CheckedIndexCollectionAdds an item to the CheckedListBox.CheckedIndexCollection. 如需這個成員的說明,請參閱 Add(Object)For a description of this member, see Add(Object).

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

CheckedListBox.CheckedIndexCollection 中移除所有項目。Removes all items from the CheckedListBox.CheckedIndexCollection. 如需這個成員的說明,請參閱 Clear()For a description of this member, see Clear().

IList.Contains(Object) IList.Contains(Object) IList.Contains(Object) IList.Contains(Object)

判斷指定的索引是否位於 CheckedListBox.CheckedIndexCollection 中。Determines whether the specified index is located within the CheckedListBox.CheckedIndexCollection. 如需這個成員的說明,請參閱 Contains(Object)For a description of this member, see Contains(Object).

IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object)

如需這個成員的說明,請參閱 IndexOf(Object)For a description of this member, see IndexOf(Object).

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.Item[Int32] IList.Item[Int32] IList.Item[Int32] IList.Item[Int32]

如需這個成員的說明,請參閱 Item[Int32]For a description of this member, see Item[Int32].

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)or a description of this member, see RemoveAt(Int32).

Extension Methods

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.

適用於

另請參閱