CheckedListBox.CheckedItemCollection Classe

Definizione

Incapsula la raccolta di elementi controllati, inclusi gli elementi in uno stato indeterminato, in un controllo CheckedListBox.

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
Ereditarietà
CheckedListBox.CheckedItemCollection
Implementazioni

Esempio

Nell'esempio seguente vengono enumerati gli elementi selezionati in CheckedListBox.CheckedIndexCollection per visualizzare lo stato di controllo in cui si trova un elemento. Nell'esempio viene illustrato l'utilizzo del GetItemCheckState metodo per impostare lo stato check di un elemento. L'esempio illustra anche l'uso della CheckedIndices proprietà per ottenere l'oggetto CheckedListBox.CheckedIndexCollectione la CheckedItems proprietà per ottenere l'oggetto CheckedListBox.CheckedItemCollection.

Il primo ciclo usa il GetItemCheckState metodo per ottenere l'oggetto CheckState di ogni elemento selezionato, dato l'indice dell'elemento. Il secondo ciclo usa GetItemCheckStateanche , ma usa il ListBox.ObjectCollection.IndexOf metodo per recuperare l'indice per l'elemento.

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

Commenti

L'insieme di elementi selezionati è un subset di tutti gli elementi del CheckedListBox controllo, che contiene solo gli elementi che si trovano in uno stato archiviato o indeterminato.

La tabella seguente è un esempio della raccolta indicizzata di elementi nel controllo (tutti gli elementi contenuti nel controllo ).

Indice Elemento Controllare lo stato
0 oggetto 1 Unchecked
1 oggetto 2 Checked
2 oggetto 3 Unchecked
3 oggetto 4 Indeterminate
4 oggetto 5 Checked

In base all'esempio precedente, la tabella seguente mostra la raccolta indicizzata degli elementi selezionati.

Indice Elemento
0 oggetto 2
1 oggetto 4
2 oggetto 5

La CheckedListBox classe dispone di due membri che consentono di accedere agli indici archiviati, alla Item[] proprietà e al IndexOf metodo .

In base all'esempio precedente, una chiamata alla proprietà con un valore di parametro pari a Item[] 1 restituisce l'oggetto 4. Una chiamata a con un parametro dell'oggetto 4 restituisce un valore pari a IndexOf 1.

Proprietà

Count

Ottiene il numero di elementi nella raccolta.

IsReadOnly

Ottiene un valore che indica se l'insieme è in sola lettura.

Item[Int32]

Ottiene un oggetto nell'insieme di elementi selezionati.

Metodi

Contains(Object)

Consente di determinare se l'elemento specificato è contenuto nell'insieme.

CopyTo(Array, Int32)

Copia l'intero insieme in una posizione specifica all'interno di una matrice esistente.

Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetEnumerator()

Restituisce un enumeratore che può essere utilizzato per scorrere l'insieme CheckedItems.

GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
IndexOf(Object)

Restituisce un indice nell'insieme di elementi selezionati.

MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

ICollection.IsSynchronized

Per una descrizione di questo membro, vedere IsSynchronized.

ICollection.SyncRoot

Per una descrizione di questo membro, vedere SyncRoot.

IList.Add(Object)

Per una descrizione di questo membro, vedere Add(Object).

IList.Clear()

Per una descrizione di questo membro, vedere Clear().

IList.Insert(Int32, Object)

Per una descrizione di questo membro, vedere Insert(Int32, Object).

IList.IsFixedSize

Per una descrizione di questo membro, vedere IsFixedSize.

IList.Remove(Object)

Per una descrizione di questo membro, vedere Remove(Object).

IList.RemoveAt(Int32)

Per una descrizione di questo membro, vedere RemoveAt(Int32).

Metodi di estensione

Cast<TResult>(IEnumerable)

Esegue il cast degli elementi di un oggetto IEnumerable nel tipo specificato.

OfType<TResult>(IEnumerable)

Filtra gli elementi di un oggetto IEnumerable in base a un tipo specificato.

AsParallel(IEnumerable)

Consente la parallelizzazione di una query.

AsQueryable(IEnumerable)

Converte un oggetto IEnumerable in un oggetto IQueryable.

Si applica a