DataGridViewColumn.SortMode 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定資料行的排序模式。
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,指定用來根據資料行中的儲存格值為資料列排序的準則。
例外狀況
指派給屬性的值與 SelectionMode 相衝突。
範例
下列程式碼範例示範如何使用 SortMode 屬性。
this.dataGridView1.Columns["Priority"].SortMode =
DataGridViewColumnSortMode.Automatic;
Me.dataGridView1.Columns("Priority").SortMode = _
DataGridViewColumnSortMode.Automatic
備註
DataGridView當控制項使用 SortMode 屬性值 Automatic 為 的資料行進行排序時,資料行標頭中會自動顯示排序圖像。
從 .NET Framework 4.6 開始,當app.config檔案包含下列專案時,會根據系統 DPI 設定來調整排序圖像的大小:
<appSettings>
<add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />
</appSettings>
當控制項使用 SortMode 屬性值為 Programmatic 的資料行進行排序時,您必須透過 SortGlyphDirection 屬性自行顯示排序圖像。
的預設排序模式 DataGridViewTextBoxColumn 為 Automatic 。 其他資料行類型的預設排序模式為 NotSortable 。
這個 SortMode 值不會防止您以程式設計方式排序資料行,但可能會套用其他限制。 如需詳細資訊,請參閱 Sort 方法。
SortMode的 NotSortable 屬性值不會防止 DataGridView.ColumnHeaderMouseClick 事件發生,但會防止標頭在按一下時變更其外觀。