Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable sort in DataGridView?

How can I disable sort in DataGridView? I need to disable the header DataGridView sorting.

like image 620
Gold Avatar asked Dec 21 '10 18:12

Gold


2 Answers

foreach (DataGridViewColumn column in dataGridView.Columns) {     column.SortMode = DataGridViewColumnSortMode.NotSortable; } 
like image 100
hunter Avatar answered Oct 02 '22 07:10

hunter


Use LINQ:

Datagridview1.Columns.Cast<DataGridViewColumn>().ToList().ForEach(f => f.SortMode = DataGridViewColumnSortMode.NotSortable); 
like image 29
Amit Bisht Avatar answered Oct 02 '22 06:10

Amit Bisht