共用方式為


如何:在 Windows Form 的 ComboBox、ListBox 或 CheckedListBox 控制項中存取特定的項目

存取 Windows Forms 下拉式方塊、清單方塊或核取方塊中的特定專案是一項基本工作。 它可讓您以程式設計方式判斷清單中位於任何指定位置的內容。

存取特定專案

  1. Items使用特定專案的索引來查詢集合:

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

另請參閱