【问题标题】:Sorting is not working for my WPF DataGrid?排序不适用于我的 WPF DataGrid?
【发布时间】:2012-03-06 08:27:32
【问题描述】:

我有一个 Datagrid。排序不适合它。

我不知道问题出在哪里。我搜索了一下。

我没有找到解决方案。

我的代码是

<toolkit:DataGrid Name="TSGrid" RowHeaderWidth="0" IsSynchronizedWithCurrentItem="True" 
                                  SelectionChanged="TSGrid_SelectionChanged" GridLinesVisibility="Horizontal" 
                                  RowHeight="25"
                                  ColumnHeaderStyle="{DynamicResource ColumnHeaderStyle}" FontSize="12" 
                                  BorderBrush="DarkGreen" BorderThickness="1" ColumnHeaderHeight="30" 
                                  IsReadOnly="True" ItemsSource="{Binding}" 
                                  CanUserAddRows="False" CanUserReorderColumns="True" SelectionMode="Single"
                                  SelectionUnit="FullRow" CanUserResizeColumns="True" 
                                  AreRowDetailsFrozen="False" RowStyle="{StaticResource RowStyle}"
                                  AutoGenerateColumns="False" LoadingRow="TSGrid_LoadingRow" Margin="4,0,0,4">

有人可以帮忙吗?

提前致谢

拉姆基

【问题讨论】:

    标签: wpfdatagrid


    【解决方案1】:

    需要将DataGrid的CanUserSortColumns属性设置为True

    【讨论】:

    • 默认情况下 CanUserSortColumns=True。我试过了。但是当我点击标题时它不起作用
    • 那么你需要将属性路径分配给SortMemberPath
    【解决方案2】:

    如果以前的答案对您不起作用,请查看下面的链接,我们的想法是在 collectionViewSource 级别定义排序 WPF DataGrid default sort not working

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-02
      • 2021-05-06
      • 1970-01-01
      • 1970-01-01
      • 2013-12-31
      • 2013-08-22
      • 2020-05-18
      • 2015-05-13
      相关资源
      最近更新 更多