星期三, 4月 20, 2016

[C#] DataGridView - 取消自動排序功能

網路問題
我想要把點colmun上面的箭頭排序消失或是點了以後不會排序,請問要怎麼做?謝謝!!!
一直覺得 DataGridView 自動排序功能很好用,沒想到要讓欄位不能排序,看到問題當下,自己也沒有頭緒要怎麼做,哈

在 DataGridView 內的 DataGridViewColumn 找到 SortMode Property,把它設為 NotSortable 就可以取消自動排序功能

DataGridViewColumn.SortMode 預設為 Automatic

[C#] DataGridView - 取消自動排序功能-1

DataGridViewColumn.SortMode 設定為 NotSortable

[C#] DataGridView - 取消自動排序功能-2

DataGridViewColumn 的排序功能就會取消

[C#] DataGridView - 取消自動排序功能-3

用語法改全部的 DataGridViewColumn SortMode Property
foreach (DataGridViewColumn col in dataGridView1.Columns)
{
    col.SortMode = DataGridViewColumnSortMode.NotSortable;
}
  • 20160723
閱讀 Visual Studio 2005 檔案 IO 與資料存取秘訣 書籍時發現,假如是
  1. DataGridViewCheckBoxColumn
  2. DataGridViewComboBoxColumn
  3. DataGridViewImageColumn
時,排序功能就顯的有點奇怪,可以考慮把該些欄位的排序功能取消

沒有留言:

張貼留言