Partilhar via


Como: Aceder a itens específicos num controlo Windows Forms ComboBox, ListBox ou CheckedListBox

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 coleção Items 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());
       }
    

Ver também