Dela via


Anvisningar: Åtkomst till specifika objekt i en ComboBox, ListBox eller CheckedListBox-kontroll för Windows Forms

Att komma åt specifika objekt i en kombinationsruta i Windows Forms, en listruta eller en markerad listruta är en viktig uppgift. Det gör att du programmatiskt kan avgöra vad som finns i en lista, vid en viss position.

Så här kommer du åt ett specifikt objekt

  1. Utför en sökning i Items-samlingen med hjälp av indexet för den specifika posten.

    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());
       }
    

Se även