Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable sorting when clicking DataGridView column header

Tags:

c#

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 has an AllowSort property. DataGridView doesn't have that. Anything I can do?

like image 642
william Avatar asked Oct 19 '10 04:10

william


3 Answers

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

dataGridView1.Columns["MyColumn"].SortMode = DataGridViewColumnSortMode.NotSortable;
like image 146
Adam Lear Avatar answered Sep 30 '22 05:09

Adam Lear


You can override OnColumnAdded function:

 protected override void OnColumnAdded(DataGridViewColumnEventArgs e)
    {
        base.OnColumnAdded(e);
        e.Column.SortMode = DataGridViewColumnSortMode.NotSortable;
    }
like image 35
Jagmag Avatar answered Sep 30 '22 06:09

Jagmag


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

like image 44
prabhuK2k Avatar answered Sep 30 '22 07:09

prabhuK2k