CheckedListBox.CheckedIndexCollection Classe
Definizione
Incapsula la raccolta di indici degli elementi controllati, inclusi gli elementi in uno stato indeterminato, in un oggetto 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
- Ereditarietà
-
CheckedListBox.CheckedIndexCollection
- Implementazioni
Esempio
Nell'esempio seguente vengono enumerati gli elementi selezionati in CheckedListBox.CheckedIndexCollection per visualizzare lo stato di selezione di un elemento.The following example enumerates the checked items in the CheckedListBox.CheckedIndexCollection to see what check state an item is in. Nell'esempio viene illustrato l'utilizzo del GetItemCheckState metodo per impostare lo stato di selezione di un elemento.The example demonstrates using the GetItemCheckState method to set the check state of an item. Nell'esempio viene inoltre illustrato l'utilizzo della CheckedIndices proprietà per ottenere l'oggetto CheckedListBox.CheckedIndexCollection e la CheckedItems proprietà per CheckedListBox.CheckedItemCollection ottenere.The example also demonstrates using the CheckedIndices property to get the CheckedListBox.CheckedIndexCollection, and the CheckedItems property to get the CheckedListBox.CheckedItemCollection.
Il primo ciclo usa il GetItemCheckState metodo per ottenere l'oggetto CheckState di ogni elemento selezionato, in base all'indice dell'elemento.The first loop uses the GetItemCheckState method to get the CheckState of each checked item, given the index of the item. Il secondo ciclo usa anche GetItemCheckState , ma usa il ListBox.ObjectCollection.IndexOf metodo per recuperare l'indice per l'elemento.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
Commenti
La raccolta di indici selezionati è un subset degli indici nella raccolta di tutti gli elementi nel CheckedListBox controllo.The checked indexes collection is a subset of the indexes into the collection of all items in the CheckedListBox control. Questi indici specificano gli elementi in uno stato selezionato o indeterminato.These indexes specify items in a checked or indeterminate state.
La tabella seguente è un esempio della raccolta indicizzata di elementi nel controllo (tutti gli elementi contenuti nel controllo).The following table is an example of the indexed collection of items in the control (all items contained in the control).
IndiceIndex | ElementoItem | Controlla statoCheck State |
---|---|---|
00 | oggetto 1object 1 | Unchecked |
11 | oggetto 2object 2 | Checked |
22 | oggetto 3object 3 | Unchecked |
33 | oggetto 4object 4 | Indeterminate |
44 | oggetto 5object 5 | Checked |
In base all'esempio precedente, nella tabella seguente viene illustrata la raccolta indicizzata di indici degli elementi selezionati.Based on the previous example, the following table shows the indexed collection of indexes of checked items.
IndiceIndex | Indice dell'elementoIndex of Item |
---|---|
00 | 11 |
11 | 33 |
22 | 44 |
La CheckedListBox classe dispone di due membri che consentono di accedere agli indici archiviati, Item[] alla proprietà e al IndexOf metodo.The CheckedListBox class has two members that allow you to access the stored indexes, the Item[] property and the IndexOf method.
In base all'esempio precedente, una chiamata alla Item[] proprietà con un valore di parametro pari a 1 restituisce un valore pari a 3.Based on the previous example, a call to the Item[] property with a parameter value of 1 returns a value of 3. Una chiamata a IndexOf con un parametro di 3 restituisce un valore pari a 1.A call to IndexOf with a parameter of 3 returns a value of 1.
Proprietà
Count |
Ottiene il numero di elementi selezionati.Gets the number of checked items. |
IsReadOnly |
Ottiene un valore che indica se la raccolta è di sola lettura.Gets a value indicating whether the collection is read-only. |
Item[Int32] |
Ottiene l'indice di un elemento selezionato nel controllo CheckedListBox.Gets the index of a checked item in the CheckedListBox control. |
Metodi
Contains(Int32) |
Consente di determinare se l'indice specificato è contenuto nell'insieme.Determines whether the specified index is located in the collection. |
CopyTo(Array, Int32) |
Copia l'intero insieme in una posizione specifica all'interno di una matrice esistente.Copies the entire collection into an existing array at a specified location within the array. |
Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object. (Ereditato da Object) |
GetEnumerator() |
Restituisce un enumeratore che può essere utilizzato per scorrere l'insieme CheckedIndices.Returns an enumerator that can be used to iterate through the CheckedIndices collection. |
GetHashCode() |
Funge da funzione hash predefinita.Serves as the default hash function. (Ereditato da Object) |
GetType() |
Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance. (Ereditato da Object) |
IndexOf(Int32) |
Restituisce un indice nell'insieme di indici selezionati.Returns an index into the collection of checked indexes. |
MemberwiseClone() |
Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object. (Ereditato da Object) |
ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente.Returns a string that represents the current object. (Ereditato da Object) |
Implementazioni dell'interfaccia esplicita
ICollection.IsSynchronized |
Ottiene un valore che indica se l'accesso a CheckedListBox.CheckedIndexCollection è sincronizzato (thread-safe).Gets a value indicating whether access to the CheckedListBox.CheckedIndexCollection is synchronized (thread safe). |
ICollection.SyncRoot |
Ottiene un oggetto che può essere utilizzato per sincronizzare l'accesso all'insieme dei controlli.Gets an object that can be used to synchronize access to the collection of controls. Per una descrizione di questo membro, vedere SyncRoot.For a description of this member, see SyncRoot. |
IList.Add(Object) |
Questa API supporta l'infrastruttura del prodotto e non è previsto che venga usata direttamente dal codice. Aggiunge un elemento a CheckedListBox.CheckedIndexCollection.Adds an item to the CheckedListBox.CheckedIndexCollection. Per una descrizione di questo membro, vedere Add(Object).For a description of this member, see Add(Object). |
IList.Clear() |
Rimuove tutti gli elementi da CheckedListBox.CheckedIndexCollection.Removes all items from the CheckedListBox.CheckedIndexCollection. Per una descrizione di questo membro, vedere Clear().For a description of this member, see Clear(). |
IList.Contains(Object) |
Determina se l'indice specificato si trova all'interno dell'oggetto CheckedListBox.CheckedIndexCollection.Determines whether the specified index is located within the CheckedListBox.CheckedIndexCollection. Per una descrizione di questo membro, vedere Contains(Object).For a description of this member, see Contains(Object). |
IList.IndexOf(Object) |
Per una descrizione di questo membro, vedere IndexOf(Object).For a description of this member, see IndexOf(Object). |
IList.Insert(Int32, Object) |
Per una descrizione di questo membro, vedere Insert(Int32, Object).For a description of this member, see Insert(Int32, Object). |
IList.IsFixedSize |
Per una descrizione di questo membro, vedere IsFixedSize.For a description of this member, see IsFixedSize. |
IList.Item[Int32] |
Per una descrizione di questo membro, vedere Item[Int32].For a description of this member, see Item[Int32]. |
IList.Remove(Object) |
Per una descrizione di questo membro, vedere Remove(Object).For a description of this member, see Remove(Object). |
IList.RemoveAt(Int32) |
Per una descrizione di questo membro, vedere il metodo RemoveAt(Int32).or a description of this member, see RemoveAt(Int32). |
Metodi di estensione
Cast<TResult>(IEnumerable) |
Esegue il cast degli elementi di un oggetto IEnumerable nel tipo specificato.Casts the elements of an IEnumerable to the specified type. |
OfType<TResult>(IEnumerable) |
Filtra gli elementi di un oggetto IEnumerable in base a un tipo specificato.Filters the elements of an IEnumerable based on a specified type. |
AsParallel(IEnumerable) |
Consente la parallelizzazione di una query.Enables parallelization of a query. |
AsQueryable(IEnumerable) |
Converte un oggetto IEnumerable in un oggetto IQueryable.Converts an IEnumerable to an IQueryable. |