CheckedListBox.CheckedItemCollection Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Incapsula la raccolta di elementi controllati, inclusi gli elementi in uno stato indeterminato, in un CheckedListBox controllo .
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 verificare lo stato di controllo in cui si trova un elemento. Nell'esempio viene illustrato l'utilizzo del GetItemCheckState metodo per impostare lo stato di controllo di un elemento. L'esempio illustra anche l'uso della CheckedIndices proprietà per ottenere l'oggetto CheckedListBox.CheckedIndexCollectione la CheckedItems proprietà per ottenere .CheckedListBox.CheckedItemCollection
Il primo ciclo usa il GetItemCheckState metodo per ottenere l'oggetto CheckState di ogni elemento selezionato, in base all'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 | Controlla 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, nella tabella seguente viene illustrata la raccolta indicizzata degli elementi selezionati.
| Indice | Elemento |
|---|---|
| 0 | oggetto 2 |
| 1 | oggetto 4 |
| 2 | oggetto 5 |
La CheckedListBox classe ha 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à
| Nome | Descrizione |
|---|---|
| Count |
Ottiene il numero di elementi nell'insieme. |
| IsReadOnly |
Ottiene un valore che indica se l'insieme è di sola lettura. |
| Item[Int32] |
Ottiene un oggetto nell'insieme di elementi selezionati. |
Metodi
| Nome | Descrizione |
|---|---|
| Contains(Object) |
Determina se l'elemento specificato si trova nella raccolta. |
| CopyTo(Array, Int32) |
Copia l'intera raccolta in una matrice esistente in una posizione specificata all'interno della matrice. |
| 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 il Type dell'istanza corrente. (Ereditato da Object) |
| IndexOf(Object) |
Restituisce un indice nell'insieme di elementi selezionati. |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
Implementazioni dell'interfaccia esplicita
| Nome | Descrizione |
|---|---|
| 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
| Nome | Descrizione |
|---|---|
| AsParallel(IEnumerable) |
Abilita la parallelizzazione di una query. |
| AsQueryable(IEnumerable) |
Converte un IEnumerable in un IQueryable. |
| Cast<TResult>(IEnumerable) |
Esegue il cast degli elementi di un IEnumerable al tipo specificato. |
| OfType<TResult>(IEnumerable) |
Filtra gli elementi di un IEnumerable in base a un tipo specificato. |