DataGridViewComboBoxCell.Items DataGridViewComboBoxCell.Items DataGridViewComboBoxCell.Items DataGridViewComboBoxCell.Items Property


取得物件,表示顯示在下拉式清單中的選項。Gets the objects that represent the selection displayed in the drop-down list.

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



下列程式碼範例示範使用DataGridViewComboBoxColumn.Items屬性,類似於此屬性。The following code example demonstrates the use of the DataGridViewComboBoxColumn.Items property, which is similar to this property. 這個範例是提供之較大範例的一部分DataGridViewComboBoxColumn類別概觀主題。This example is part of a larger example available in the DataGridViewComboBoxColumn class overview topic.

    void SetAlternateChoicesUsingItems(
        DataGridViewComboBoxColumn^ comboboxColumn)
        comboboxColumn->Items->AddRange("Mr.", "Ms.", "Mrs.", "Dr.");

    DataGridViewComboBoxColumn^ CreateComboBoxColumn()
        DataGridViewComboBoxColumn^ column =
            gcnew DataGridViewComboBoxColumn();
            column->DataPropertyName = ColumnName::TitleOfCourtesy.ToString();
            column->HeaderText = ColumnName::TitleOfCourtesy.ToString();
            column->DropDownWidth = 160;
            column->Width = 90;
            column->MaxDropDownItems = 3;
            column->FlatStyle = FlatStyle::Flat;
        return column;
private static void SetAlternateChoicesUsingItems(
    DataGridViewComboBoxColumn comboboxColumn)
    comboboxColumn.Items.AddRange("Mr.", "Ms.", "Mrs.", "Dr.");

private DataGridViewComboBoxColumn CreateComboBoxColumn()
    DataGridViewComboBoxColumn column =
        new DataGridViewComboBoxColumn();
        column.DataPropertyName = ColumnName.TitleOfCourtesy.ToString();
        column.HeaderText = ColumnName.TitleOfCourtesy.ToString();
        column.DropDownWidth = 160;
        column.Width = 90;
        column.MaxDropDownItems = 3;
        column.FlatStyle = FlatStyle.Flat;
    return column;
Private Shared Sub SetAlternateChoicesUsingItems( _
    ByVal comboboxColumn As DataGridViewComboBoxColumn)

    comboboxColumn.Items.AddRange("Mr.", "Ms.", "Mrs.", "Dr.")

End Sub

Private Function CreateComboBoxColumn() _
    As DataGridViewComboBoxColumn
    Dim column As New DataGridViewComboBoxColumn()

    With column
        .DataPropertyName = ColumnName.TitleOfCourtesy.ToString()
        .HeaderText = ColumnName.TitleOfCourtesy.ToString()
        .DropDownWidth = 160
        .Width = 90
        .MaxDropDownItems = 3
        .FlatStyle = FlatStyle.Flat
    End With
    Return column
End Function


此屬性可讓您取得目前儲存在中的項目清單的參考DataGridViewComboBoxCellThis property enables you to obtain a reference to the list of items that are currently stored in the DataGridViewComboBoxCell. 與這個參考中,您可以將項目加入、 移除項目,並取得集合中的項目計數。With this reference, you can add items, remove items, and obtain a count of the items in the collection. 如需詳細資訊,可使用執行的工作Items集合,請參閱DataGridViewComboBoxCell.ObjectCollectionFor more information on the tasks that can be performed with the Items collection, see DataGridViewComboBoxCell.ObjectCollection.

如果將字串新增至Items,然後ValueMemberDisplayMember不需要設定,因為每個加入的字串將會用於值和顯示。If strings are added to Items, then ValueMember and DisplayMember do not need to be set because each string added will be used for both value and display.


DataGridViewComboBoxCell 不支援使用多個具有相同的顯示值的項目。DataGridViewComboBoxCell does not support the use of multiple items with identical display values.

如果DataSource屬性設定,則Items屬性不能使用。If the DataSource property is set, then the Items property cannot be used.

儲存格的格式化的值必須永遠是在值的其中一個Items集合或錯誤,就會發生,且儲存格的值將會還原為集合中的第一個項目。The formatted value of the cell must always be one of the values in the Items collection or an error will occur and the cell value will revert to the first item in the collection. 您可以自訂此行為,藉由處理DataGridView.DataErrorDataGridView.CellFormatting事件。You can customize this behavior by handling the DataGridView.DataError and DataGridView.CellFormatting events.

將此屬性的父資料行的值以外的值設Items屬性將會強制該資料列變為非共用,配置額外的記憶體。Setting this property to a value other than the value of the parent column's Items property will force the row to become unshared, allocating extra memory. 如需有關共用資料列的詳細資訊,請參閱縮放 Windows Form DataGridView 控制項的最佳作法For more information about row sharing, see Best Practices for Scaling the Windows Forms DataGridView Control.