DataGridViewColumn.SortMode DataGridViewColumn.SortMode DataGridViewColumn.SortMode DataGridViewColumn.SortMode Property

定义

获取或设置列的排序模式。Gets or sets the sort mode for the column.

public:
 property System::Windows::Forms::DataGridViewColumnSortMode SortMode { System::Windows::Forms::DataGridViewColumnSortMode get(); void set(System::Windows::Forms::DataGridViewColumnSortMode value); };
public System.Windows.Forms.DataGridViewColumnSortMode SortMode { get; set; }
member this.SortMode : System.Windows.Forms.DataGridViewColumnSortMode with get, set
Public Property SortMode As DataGridViewColumnSortMode

属性值

DataGridViewColumnSortMode,指定根据列中单元格的值对行进行排序的条件。A DataGridViewColumnSortMode that specifies the criteria used to order the rows based on the cell values in a column.

异常

分配给属性的值与 SelectionMode 冲突。The value assigned to the property conflicts with SelectionMode.

示例

下面的代码示例演示如何使用SortMode属性。The following code example demonstrates how to use the SortMode property.

this.dataGridView1.Columns["Priority"].SortMode =
    DataGridViewColumnSortMode.Automatic;
Me.dataGridView1.Columns("Priority").SortMode = _
    DataGridViewColumnSortMode.Automatic

注解

当使用SortMode属性值为的Automatic列对控件进行排序时,排序标志符号会自动显示在列标题中。DataGridViewWhen a DataGridView control is sorted using a column with a SortMode property value of Automatic, a sorting glyph is automatically displayed in the column header.

从 .NET Framework 4.6 开始,当 app.config 文件包含以下项时,将根据系统 DPI 设置调整排序标志符号的大小:Starting in the .NET Framework 4.6, the sorting glyph is resized according to the system DPI settings when the app.config file contains the following entry:

<appSettings>  
  <add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />  
</appSettings>  

当使用SortMode属性值为的Programmatic列对控件进行排序时,必须通过SortGlyphDirection属性自行显示排序标志符号。When the control is sorted using a column with a SortMode property value of Programmatic, you must display the sorting glyph yourself through the SortGlyphDirection property.

的默认排序模式DataGridViewTextBoxColumn为。 AutomaticThe default sort mode of a DataGridViewTextBoxColumn is Automatic. 其他列类型的默认排序模式为NotSortableThe default sort mode for other column types is NotSortable.

SortMode该值不会阻止以编程方式对列进行排序,但其他限制可能适用。The SortMode value does not prevent you from sorting a column programmatically, although other restrictions may apply. 有关更多信息,请参见 Sort 方法。For more information, see the Sort method.

属性值不DataGridView.ColumnHeaderMouseClick会阻止事件发生,但会阻止标题在单击时更改其外观。 NotSortable SortModeA SortMode property value of NotSortable will not prevent the DataGridView.ColumnHeaderMouseClick event from occurring, but it will prevent the header from changing its appearance when it is clicked.

适用于

另请参阅