Compartilhar via


Como acessar itens específicos em um controle ComboBox, ListBox ou CheckedListBox dos Windows Forms

Acessar itens específicos em uma caixa de combinação, caixa de listagem ou caixa de listagem marcada do Windows Forms é uma tarefa essencial. Ele permite que você determine programaticamente o que está em uma lista, em qualquer posição.

Para acessar um item específico

  1. Consulte a Items coleção usando o índice do item específico:

    Private Function GetItemText(i As Integer) As String
       ' Return the text of the item using the index:
       Return ComboBox1.Items(i).ToString
    End Function
    
    private string GetItemText(int i)
    {
       // Return the text of the item using the index:
       return (comboBox1.Items[i].ToString());
    }
    
    private:
       String^ GetItemText(int i)
       {
          // Return the text of the item using the index:
          return (comboBox1->Items->Item[i]->ToString());
       }
    

Consulte também