Gewusst wie: Zugreifen auf spezifische Elemente in ComboBox-, ListBox- oder CheckedListBox-Steuerelementen in Windows Forms

Eine der grundlegenden Tasks ist das Zugreifen auf spezifische Elemente in Kombinationsfeldern, Listenfeldern oder aktivierten Listenfeldern von Windows Forms. Sie können programmgesteuert bestimmen, welches Element sich an einer gegebenen Position in der Liste befindet.

So greifen Sie auf ein spezifisches Element zu

  • Fragen Sie die Items -Auflistung mithilfe des Indizes des jeweiligen Elements ab:

    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.get_Items().get_Item( i).ToString() ;
    }
    
    private:
       String^ GetItemText(int i)
       {
          // Return the text of the item using the index:
          return (comboBox1->Items->Item[i]->ToString());
       }
    

Siehe auch

Referenz

ComboBox

ListBox

CheckedListBox

Weitere Ressourcen

Steuerelemente in Windows Forms zum Auflisten von Optionen