CheckedListBox.CheckedIndexCollection Classe

Definição

Encapsula a coleção de índices de itens verificados (incluindo itens em um estado indeterminado) em um 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
Herança
CheckedListBox.CheckedIndexCollection
Implementações

Exemplos

O exemplo a CheckedListBox.CheckedIndexCollection seguir enumera os itens verificados no estado de verificação em que um item está. O exemplo demonstra o uso do GetItemCheckState método para definir o estado de verificação de um item. O exemplo também demonstra o uso da CheckedIndices propriedade para obter a CheckedListBox.CheckedIndexCollectionpropriedade e a CheckedItems propriedade para obter o CheckedListBox.CheckedItemCollection.

O primeiro loop usa o GetItemCheckState método para obter o CheckState de cada item verificado, considerando o índice do item. O segundo loop também usa GetItemCheckState, mas usa o ListBox.ObjectCollection.IndexOf método para recuperar o índice do 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

Comentários

A coleção de índices verificados é um subconjunto dos índices na coleção de todos os itens no CheckedListBox controle. Esses índices especificam itens em um estado verificado ou indeterminado.

A tabela a seguir é um exemplo da coleção indexada de itens no controle (todos os itens contidos no controle).

Índice Item Verificar Estado
0 objeto 1 Unchecked
1 objeto 2 Checked
2 objeto 3 Unchecked
3 objeto 4 Indeterminate
4 objeto 5 Checked

Com base no exemplo anterior, a tabela a seguir mostra a coleção indexada de índices de itens verificados.

Índice Índice de Item
0 1
1 3
2 4

A CheckedListBox classe tem dois membros que permitem acessar os índices armazenados, a Item[] propriedade e o IndexOf método.

Com base no exemplo anterior, uma chamada à Item[] propriedade com um valor de parâmetro de 1 retorna um valor de 3. Uma chamada com IndexOf um parâmetro de 3 retorna um valor de 1.

Propriedades

Count

Obtém o número de itens selecionados.

IsReadOnly

Obtém um valor que indica se a coleção é somente leitura.

Item[Int32]

Obtém o índice de um item selecionado no controle CheckedListBox.

Métodos

Contains(Int32)

Determina se o índice especificado está localizado na coleção.

CopyTo(Array, Int32)

Copia toda a coleção em uma matriz existente de um local especificado na matriz.

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetEnumerator()

Retorna um enumerador que pode ser usado para iterar na coleção CheckedIndices.

GetHashCode()

Serve como a função de hash padrão.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IndexOf(Int32)

Retorna um índice na coleção de índices selecionados.

MemberwiseClone()

Cria uma cópia superficial do Object atual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Implantações explícitas de interface

ICollection.IsSynchronized

Obtém um valor que indica se o acesso à CheckedListBox.CheckedIndexCollection é sincronizado (thread-safe).

ICollection.SyncRoot

Obtém um objeto que pode ser usado para sincronizar o acesso à coleção de controels. Para obter uma descrição desse membro, confira SyncRoot.

IList.Add(Object)

Esta API dá suporte à infraestrutura do produto e não deve ser usada diretamente do seu código.

Adiciona um item ao CheckedListBox.CheckedIndexCollection. Para obter uma descrição desse membro, confira Add(Object).

IList.Clear()

Remove todos os itens do CheckedListBox.CheckedIndexCollection. Para obter uma descrição desse membro, confira Clear().

IList.Contains(Object)

Determina se o índice especificado está localizado dentro do CheckedListBox.CheckedIndexCollection. Para obter uma descrição desse membro, confira Contains(Object).

IList.IndexOf(Object)

Para obter uma descrição desse membro, confira IndexOf(Object).

IList.Insert(Int32, Object)

Para obter uma descrição desse membro, confira Insert(Int32, Object).

IList.IsFixedSize

Para obter uma descrição desse membro, confira IsFixedSize.

IList.Item[Int32]

Para obter uma descrição desse membro, confira Item[Int32].

IList.Remove(Object)

Para obter uma descrição desse membro, confira Remove(Object).

IList.RemoveAt(Int32)

Para obter uma descrição deste membro, consulte RemoveAt(Int32).

Métodos de Extensão

Cast<TResult>(IEnumerable)

Converte os elementos de um IEnumerable para o tipo especificado.

OfType<TResult>(IEnumerable)

Filtra os elementos de um IEnumerable com base em um tipo especificado.

AsParallel(IEnumerable)

Habilita a paralelização de uma consulta.

AsQueryable(IEnumerable)

Converte um IEnumerable em um IQueryable.

Aplica-se a

Confira também