Making a DataGrid Column Header sortable in WPF using C#

后端 未结 1 904
孤街浪徒
孤街浪徒 2021-01-01 10:15

I am using C# in Visual Studio 2008 and I have install the WPF Toolkit. I created a DataGrid in testtest.xaml. The ID and Parts $ columns have the ability to sort the Dat

相关标签:
1条回答
  • 2021-01-01 10:49

    In your DataGridTemplateColumn you have SortMemberPath set to "". If you set this to an actual property on the item (say, CompleteDate), you should be able to sort. You can also set CanUserSort="true" or CanUserSort="false" on selected columns.

    SortMemberPath gives the property to sort on when the user attempts a sort. If this isn't set, then the grid doesn't know how to sort that column ( it does not use the text in the column)

                <my:DataGridTemplateColumn  SortMemberPath="CompleteDate" Header="Complete Date" CanUserSort="true">
                <my:DataGridTemplateColumn.CellTemplate >
                        <DataTemplate>
                            <TextBlock>
                                <TextBlock.Text>
                                    <Binding Path="CompleteDate" ConverterCulture="en-GB" StringFormat="{}{0:MM/dd/yyyy}"/>
                                </TextBlock.Text>
                            </TextBlock>
                        </DataTemplate>
                    </my:DataGridTemplateColumn.CellTemplate>
                </my:DataGridTemplateColumn>
    
    0 讨论(0)
提交回复
热议问题