DataGridViewComboBoxColumn.Items 属性

定义

获取用作组合框中选项的对象的集合。

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

属性值

DataGridViewComboBoxCell.ObjectCollection

DataGridViewComboBoxCell.ObjectCollection,它表示组合框中的选项。

例外

CellTemplate 属性的值为 null

示例

下面的代码示例演示如何使用 a DataGridViewComboBoxColumn 来帮助将数据输入到 TitleOfCourtesy 列中。 该 Items 属性用于使用所选标题填充组合框下拉列表。 此示例是类概述主题中可用的较大示例的 DataGridViewComboBoxColumn 一部分。

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

private:
    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

注解

此属性返回属性返回CellTemplate的属性的值。Items DataGridViewComboBoxCell

ItemsDataSource属性用于填充组合框的选择。

如果将字符串添加到 Items其中,则 ValueMember 不需要设置和 DisplayMember 属性,因为添加的每个字符串将同时用于值和显示。

备注

DataGridViewComboBoxColumn 不支持使用具有相同显示值的多个项。

如果设置了该 DataSource 属性, Items 则不能使用。

适用于

另请参阅