Can a DataGrid's template column be sortable?

Jul 30, 2009 at 7:01 AM


I'm trying to make a template column in a DataGrid sortable, but it does not seem to work. When I click on it, the background of the column header will not be highlighted and the Sorting event is also not fired. Am I making something wrong or does the DataGrid not support sorting for template columns?

<Controls:DataGrid Sorting="DataGrid_Sorting">
        <Controls:DataGridTextColumn Header="Hello" />
        <Controls:DataGridTemplateColumn Header="World">
                    <Button Content="Test" />

Best Regards
Oliver Hanappi

Jul 30, 2009 at 7:25 AM

You need to set SortMemberPath for sorting on template columns to work. Otherwise, the DataGrid has no knowledge of what the actual user-interpretable content of the cell is.

Jul 30, 2009 at 7:52 AM

Thank you for your help, now it's working!

Jul 30, 2009 at 8:30 AM

You are welcome. Glad I could help!