共用方式為


如何:在 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());
       }
    

另請參閱