How to disable sort in DataGridView?
foreach (DataGridViewColumn column in dataGridView.Columns)
{
column.SortMode = DataGridViewColumnSortMode.NotSortable;
}
Use LINQ:
Datagridview1.Columns.Cast<DataGridViewColumn>().ToList().ForEach(f => f.SortMode = DataGridViewColumnSortMode.NotSortable);
If you want statically make columns not sortable. You can do this way
- Open the EditColumns window of the DataGridView control.
- Select the column you want to make not sortable on the left side pane.
- In the right side properties pane, select the Sort Mode property and select "Not Sortable" in that.