Best way to disable the column header sorting in DataGridView

Ananth picture Ananth · Dec 2, 2010 · Viewed 84.8k times · Source

I need to disable the column header sorting in DataGridView.

We can do that by setting the property of individual columns like

BalancesGridView.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;

If this is the case , then I'll have to loop through all the columns.

Is there a better way ?

Answer

bitbonk picture bitbonk · Dec 2, 2010

No, I think setting the SortMode on the column directly is as good as it gets. But honestly, who cares? What's so bad about a simple loop?