Disable sorting when clicking DataGridView column header

后端 未结 3 659
春和景丽
春和景丽 2020-12-19 02:17

I have a DataGridView column header. When I click that header, the data is resorted according to the value.

I don\'t want that.

DataGrid

相关标签:
3条回答
  • 2020-12-19 02:27

    You can override OnColumnAdded function:

     protected override void OnColumnAdded(DataGridViewColumnEventArgs e)
        {
            base.OnColumnAdded(e);
            e.Column.SortMode = DataGridViewColumnSortMode.NotSortable;
        }
    
    0 讨论(0)
  • 2020-12-19 02:30

    You can disable auto sort for each and every individual cells in your DataGridView:

    0 讨论(0)
  • 2020-12-19 02:45

    You have to set that on the columns. For example,

    dataGridView1.Columns["MyColumn"].SortMode = DataGridViewColumnSortMode.NotSortable;
    
    0 讨论(0)
提交回复
热议问题