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 ?
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.
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.
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With