編集

次の方法で共有


DataGridViewComboBoxCell.Sorted Property

Definition

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

Property Value

true if the combo box is sorted; otherwise, false. The default is false.

Exceptions

An attempt was made to sort a cell that is attached to a data source.

Examples

The following code example demonstrates the use of the DataGridViewComboBoxColumn.Sorted property, which is similar to this property. 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

Remarks

This property specifies whether the hosted DataGridViewComboBoxEditingControl sorts existing entries and add new entries to the appropriate sorted position in the list. 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.

Applies to

See also