DataGridViewComboBoxCell.MaxDropDownItems 属性

定义

获取或设置下拉列表中显示的最大项数。

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

属性值

Int32

所允许的下拉列表项数。 最小是 1,最大是 100,默认值是 8。

例外

设置此属性时该值小于 1 或大于 100。

示例

下面的代码示例演示了属性 DataGridViewComboBoxColumn.MaxDropDownItems 的使用,该属性类似于此属性。 此示例是类概述主题中可用的较大示例的 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更改该属性将更改托管DataGridViewComboBoxEditingControl的相应MaxDropDownItems属性。

适用于

另请参阅