Search code examples
wpfwpfdatagrid

DataGrid Sorting on HeaderClick


Is it possible to restrict DataGrid sorting to limited columns? For example, If I have columns 1, 2 and 3. I only want data to sort when user clicks header of column 1 and 2 and nothing should happen when header of column 3 is clicked.

Also how can I get the information which column is currently sorted.

Thanks


Solution

  • +1 from me for the question even though it is probably a duplicate.

    Every DataGrid column allows to specify if user shall be able to sort the column.

    Take a look at this link.

    http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridcolumn.canusersort%28v=vs.110%29.aspx

    Now in order to disable sorting just set DataGridColumn.CanUserSort to false.