Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable sorting on autogenerated columns in DataGrid in WPF MVVM

I have a DataGrid in WPF with autogenerated columns.

How can I disable sorting functionality of all the rows following the MVVM pattern?

<DataGrid AutoGenerateColumns="True" 
            ItemsSource="{Binding MyList}" 
</DataGrid>
like image 588
AxdorphCoder Avatar asked Sep 04 '14 09:09

AxdorphCoder


People also ask

How to disable sorting in DataGrid WPF?

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 do I sort a column in DataGrid WPF?

WPF DataGrid (SfDataGrid) allows you to sort the data against one or more columns either in ascending or descending order. The sorting can be performed by clicking a column header. You can enable/disable the sorting for all the columns in DataGrid by using DataGrid. AllowSorting property.

Can user reorder columns WPF?

RadGridView supports column reordering and it can be done by the user in run-time. The user can drag the desired column's header at the desired position among the other headers and drop it there.

What is data Grid in WPF?

A DataGrid is a control that displays data in a customizable grid. It provides a flexible way to display a collection of data in rows and columns. The hierarchical inheritance of DataGrid class is as follows −


1 Answers

Set CanUserSortColumns="False" on dataGrid which will disable sorting for all columns.

<DataGrid AutoGenerateColumns="True" 
          ItemsSource="{Binding MyList}"
          CanUserSortColumns="False">
</DataGrid>
like image 124
Rohit Vats Avatar answered Sep 28 '22 07:09

Rohit Vats