ComboBox.Items 屬性

定義

取得物件,代表包含於這個 ComboBox 中的項目集合。Gets an object representing the collection of the items contained in this ComboBox.

public:
 property System::Windows::Forms::ComboBox::ObjectCollection ^ Items { System::Windows::Forms::ComboBox::ObjectCollection ^ get(); };
public System.Windows.Forms.ComboBox.ObjectCollection Items { get; }
member this.Items : System.Windows.Forms.ComboBox.ObjectCollection
Public ReadOnly Property Items As ComboBox.ObjectCollection

屬性值

ComboBox.ObjectCollection,代表 ComboBox 中的項目。A ComboBox.ObjectCollection representing the items in the ComboBox.

範例

下列程式碼範例示範如何加入少量的 ComboBox 專案。The following code example demonstrates how to add a small number of ComboBox items. 如果您需要新增大量專案,請參閱 BeginUpdate的範例。If you need to add a large number of items, see the example at BeginUpdate. 這兩個範例都是 ComboBox 類別總覽中提供之較大範例的一部分。Both examples are part of a larger example available in the ComboBox class overview.

void addButton_Click( Object^ sender, System::EventArgs^ e )
{
   comboBox1->Items->Add( textBox1->Text );
}
private void addButton_Click(object sender, System.EventArgs e) {
   comboBox1.Items.Add(textBox1.Text);
}
Private Sub addButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    comboBox1.Items.Add(textBox1.Text)
End Sub

備註

這個屬性可讓您取得目前儲存在 ComboBox中之專案清單的參考。This property enables you to obtain a reference to the list of items that are currently stored in the ComboBox. 使用此參考,您可以加入專案、移除專案,以及取得集合中的專案計數。With this reference, you can add items, remove items, and obtain a count of the items in the collection.

雖然 ComboBox 通常用來顯示文字專案,但您可以將任何物件加入至 ComboBoxAlthough the ComboBox is typically used to display text items, you can add any object to the ComboBox. 一般來說,ComboBox 中的物件標記法是該物件之 ToString 方法所傳回的字串。Typically, the representation of an object in the ComboBox is the string returned by that object's ToString method. 如果您想要改為顯示物件的成員,請選擇要顯示的成員,方法是將 [DisplayMember] 屬性設定為適當成員的名稱。If you want to have a member of the object displayed instead, choose the member that will be displayed by setting the DisplayMember property to the name of the appropriate member. 您也可以藉由設定 ValueMember 屬性,選擇將代表物件所傳回之值的物件成員。You can also choose a member of the object that will represent the value returned by the object by setting the ValueMember property. 如需詳細資訊,請參閱ListControlFor more information, see ListControl.

如需可使用專案集合執行之工作的詳細資訊,請參閱 System.Windows.Forms.ComboBox.ObjectCollection 類別參考主題。For more information about the tasks that can be performed with the item collection, see the System.Windows.Forms.ComboBox.ObjectCollection class reference topics.

適用於