DataGridViewColumn.SortMode 屬性

定義

取得或設定資料行的排序模式。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

備註

DataGridView 控制項使用具有 SortMode 屬性值 Automatic的資料行進行排序時,資料行標頭中會自動顯示排序圖像。When 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>  

當控制項使用具有 ProgrammaticSortMode 屬性值的資料行進行排序時,您必須透過 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.

NotSortableSortMode 屬性值不會防止發生 DataGridView.ColumnHeaderMouseClick 事件,但它會防止標頭在按一下時變更其外觀。A 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.

適用於

另請參閱