Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to disable the column header sorting in DataGridView [duplicate]

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 ?

like image 625
Ananth Avatar asked Dec 02 '10 12:12

Ananth


People also ask

How to disable column sorting in DataGridView in c#?

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.

How do I stop sorting in DataGrid?

Disabling Column Sorting | ComponentOne DataGrid for WPF and Silverlight. By default end users can sort columns in the grid at run time. For more information, see Sorting Columns. If you choose, however, you can disable the column sorting feature by setting the CanUserSort property to False.

How to order DataGridView columns in c#?

The DataGridView control in C# provides automatic sorting, so that you can manually sort any column in the datagridview control. You can sort the data in ascending or descending order based on the contents of the specified column. Also you can see the DataGridView sorting when user clicks on the column header.


1 Answers

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?

like image 102
bitbonk Avatar answered Sep 26 '22 09:09

bitbonk