DataGridViewComboBoxCell.Sorted 屬性

定義

取得或設定值,指出是否會為下拉式方塊中的項目自動排序。Gets or sets a value indicating whether the items in the combo box are automatically sorted.

public:
 virtual property bool Sorted { bool get(); void set(bool value); };
public virtual bool Sorted { get; set; }
member this.Sorted : bool with get, set
Public Overridable Property Sorted As Boolean

屬性值

如果下拉式方塊已排序,則為 true,否則為 falsetrue if the combo box is sorted; otherwise, false. 預設為 falseThe default is false.

例外狀況

嘗試對附加至資料來源的儲存格進行排序。An attempt was made to sort a cell that is attached to a data source.

範例

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

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

備註

這個屬性會指定裝載的DataGridViewComboBoxEditingControl是否會排序現有的專案,並將新的專案加入至清單中的適當排序位置。This property specifies whether the hosted DataGridViewComboBoxEditingControl sorts existing entries and add new entries to the appropriate sorted position in the list. 當這個屬性設定為false時,新的專案就會加入至現有清單的結尾。When this property is set to false, new items are added to the end of the existing list. 排序作業不區分大小寫,而且會依字母順序以遞增循序執行。The sorting operation is case-insensitive and performed in alphabetically ascending order.

適用於

另請參閱