共用方式為


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 屬性。

適用於

另請參閱