CheckedListBox.CheckedItemCollection Klasa
Definicja
Hermetyzuje kolekcję zaznaczonych elementów, w tym elementy w nieokreślonym stanie, w CheckedListBox kontrolce.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
- Dziedziczenie
-
CheckedListBox.CheckedItemCollection
- Implementuje
Przykłady
Poniższy przykład wylicza zaznaczone elementy w programie, CheckedListBox.CheckedIndexCollection Aby zobaczyć, jaki jest stan zaznaczenia elementu.The following example enumerates the checked items in the CheckedListBox.CheckedIndexCollection to see what check state an item is in. Przykład ilustruje użycie GetItemCheckState metody w celu ustawienia stanu sprawdzania elementu.The example demonstrates using the GetItemCheckState method to set the check state of an item. W przykładzie pokazano również CheckedIndices , jak użyć właściwości, aby pobrać CheckedListBox.CheckedIndexCollection i CheckedItems Właściwość w celu uzyskania CheckedListBox.CheckedItemCollection .The example also demonstrates using the CheckedIndices property to get the CheckedListBox.CheckedIndexCollection, and the CheckedItems property to get the CheckedListBox.CheckedItemCollection.
Pierwsza pętla używa GetItemCheckState metody, aby uzyskać CheckState każdy zaznaczony element, na podstawie indeksu elementu.The first loop uses the GetItemCheckState method to get the CheckState of each checked item, given the index of the item. Druga pętla również używa GetItemCheckState , ale używa ListBox.ObjectCollection.IndexOf metody, aby pobrać indeks dla elementu.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
Uwagi
Kolekcja Checked Items jest podzbiorem wszystkich elementów w CheckedListBox kontrolce; zawiera tylko te elementy, które są w stanie sprawdzonym lub nieokreślonym.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.
Poniższa tabela stanowi przykład indeksowanej kolekcji elementów w kontrolce (wszystkie elementy zawarte w kontrolce).The following table is an example of the indexed collection of items in the control (all items contained in the control).
IndeksIndex | ElementItem | Sprawdź stanCheck State |
---|---|---|
00 | Obiekt 1object 1 | Unchecked |
11 | Obiekt 2object 2 | Checked |
22 | Obiekt 3object 3 | Unchecked |
33 | Obiekt 4object 4 | Indeterminate |
44 | Obiekt 5object 5 | Checked |
Na podstawie poprzedniego przykładu w poniższej tabeli przedstawiono indeksowaną kolekcję zaznaczonych elementów.Based on the previous example, the following table shows the indexed collection of the checked items.
IndeksIndex | ElementItem |
---|---|
00 | Obiekt 2object 2 |
11 | Obiekt 4object 4 |
22 | Obiekt 5object 5 |
CheckedListBoxKlasa ma dwa elementy członkowskie, które umożliwiają dostęp do przechowywanych indeksów, Item[] właściwości i IndexOf metody.The CheckedListBox class has two members that allow you to access the stored indexes, the Item[] property and the IndexOf method.
Na podstawie poprzedniego przykładu wywołanie Item[] właściwości z wartością parametru 1 zwraca obiekt 4.Based on the previous example, a call to the Item[] property with a parameter value of 1 returns object 4. Wywołanie IndexOf z parametrem obiektu 4 zwraca wartość 1.A call to IndexOf with a parameter of object 4 returns a value of 1.
Właściwości
Count |
Pobiera liczbę elementów w kolekcji.Gets the number of items in the collection. |
IsReadOnly |
Pobiera wartość wskazującą, czy kolekcja jest tylko do odczytu.Gets a value indicating if the collection is read-only. |
Item[Int32] |
Pobiera obiekt z kolekcji Checked Items.Gets an object in the checked items collection. |
Metody
Contains(Object) |
Określa, czy określony element znajduje się w kolekcji.Determines whether the specified item is located in the collection. |
CopyTo(Array, Int32) |
Kopiuje całą kolekcję do istniejącej tablicy w określonej lokalizacji w tablicy.Copies the entire collection into an existing array at a specified location within the array. |
Equals(Object) |
Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.Determines whether the specified object is equal to the current object. (Odziedziczone po Object) |
GetEnumerator() |
Zwraca moduł wyliczający, który może być używany do iteracji CheckedItems kolekcji.Returns an enumerator that can be used to iterate through the CheckedItems collection. |
GetHashCode() |
Służy jako domyślna funkcja skrótu.Serves as the default hash function. (Odziedziczone po Object) |
GetType() |
Pobiera Type bieżące wystąpienie.Gets the Type of the current instance. (Odziedziczone po Object) |
IndexOf(Object) |
Zwraca indeks do kolekcji zaznaczonych elementów.Returns an index into the collection of checked items. |
MemberwiseClone() |
Tworzy skróconą kopię bieżącego elementu Object .Creates a shallow copy of the current Object. (Odziedziczone po Object) |
ToString() |
Zwraca ciąg reprezentujący bieżący obiekt.Returns a string that represents the current object. (Odziedziczone po Object) |
Jawne implementacje interfejsu
ICollection.IsSynchronized |
Aby uzyskać opis tego elementu członkowskiego, zobacz IsSynchronized .For a description of this member, see IsSynchronized. |
ICollection.SyncRoot |
Aby uzyskać opis tego elementu członkowskiego, zobacz SyncRoot .For a description of this member, see SyncRoot. |
IList.Add(Object) |
Aby uzyskać opis tego elementu członkowskiego, zobacz Add(Object) .For a description of this member, see Add(Object). |
IList.Clear() |
Aby uzyskać opis tego elementu członkowskiego, zobacz Clear() .For a description of this member, see Clear(). |
IList.Insert(Int32, Object) |
Aby uzyskać opis tego elementu członkowskiego, zobacz Insert(Int32, Object) .For a description of this member, see Insert(Int32, Object). |
IList.IsFixedSize |
Aby uzyskać opis tego elementu członkowskiego, zobacz IsFixedSize .For a description of this member, see IsFixedSize. |
IList.Remove(Object) |
Aby uzyskać opis tego elementu członkowskiego, zobacz Remove(Object) .For a description of this member, see Remove(Object). |
IList.RemoveAt(Int32) |
Aby uzyskać opis tego elementu członkowskiego, zobacz RemoveAt(Int32) .For a description of this member, see RemoveAt(Int32). |
Metody rozszerzania
Cast<TResult>(IEnumerable) |
Rzutuje elementy elementu IEnumerable do określonego typu.Casts the elements of an IEnumerable to the specified type. |
OfType<TResult>(IEnumerable) |
Filtruje elementy IEnumerable w oparciu o określony typ.Filters the elements of an IEnumerable based on a specified type. |
AsParallel(IEnumerable) |
Włącza przetwarzanie równoległe zapytania.Enables parallelization of a query. |
AsQueryable(IEnumerable) |
Konwertuje IEnumerable do IQueryable .Converts an IEnumerable to an IQueryable. |