DataGridViewComboBoxColumn.MaxDropDownItems 属性

定义

获取或设置列的单元格中下拉列表的最大项数。

public:
 property int MaxDropDownItems { int get(); void set(int value); };
public int MaxDropDownItems { get; set; }
member this.MaxDropDownItems : int with get, set
Public Property MaxDropDownItems As Integer

属性值

下拉列表的最大项数,范围从 1 到 100。 默认值为 8。

例外

CellTemplate 属性的值为 null

示例

下面的代码示例演示如何使用 DataGridViewComboBoxColumn 来帮助将数据输入 TitleOfCourtesy 列。 此示例是类概述主题中提供的更大示例的 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

注解

获取或设置此属性获取或设置 MaxDropDownItems 属性 CellTemplate 返回的 对象的 属性。 设置此属性还会设置 MaxDropDownItems 列中每个单元格的 属性。 若要替代单个单元格的指定值,请在设置列值后设置单元格值。

适用于

另请参阅