DataGridTemplateColumn & Sort

Mar 15, 2009 at 12:33 PM

In Vincent Sibal's V1 compatible (january 2009) "DataGridCTPSample"  (*), in the file "DataGridBasicSample_Demo2.xaml", I duplicated the column "Last Name" as follows :

                <dg:DataGridTextColumn Width="Auto" Header="Last Name" Binding="{Binding Path=LastName}" />
                <dg:DataGridTemplateColumn Width="Auto" Header="Last Name" CanUserSort="True">
                    <dg:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=LastName}"/>
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellTemplate>
                </dg:DataGridTemplateColumn>

Outcome : the first column "Last Name" accepts "sort" (click on header), the second one apparently does not. Any reason ?

Thanks,

Julie

(*) ZIP attached to http://blogs.msdn.com/vinsibal/archive/2008/08/19/wpf-datagrid-stock-and-template-columns.aspx

Coordinator
Mar 16, 2009 at 2:22 AM
For DataGridTemplateColumn you need to set the SortMemberPath DP explicitly.
Mar 16, 2009 at 7:42 AM

The following works indeed : SortMemberPath="LastName" with CanUserSort="True" being superfluous.

Vincent, thanks,

Julie