【WPF Toolkit】怎样点击DataGrid的ColumnHeader排序?

nanhe0065 2010-02-05 04:32:16
Winform的DataGridView天生就支持,WPF的DataGrid除了
<dg:DataGridTextColumn Header="Product Name" Binding="{Binding ProductName}" CanUserSort="True" />
CanUserSort="True"之外,还要编写代码吗?
...全文
415 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
QQ422860240 2012-10-09
  • 打赏
  • 举报
回复
除CanUserSort="True"之外,还有SortMemberPath="列名"
nanhe0065 2010-03-09
  • 打赏
  • 举报
回复
DataGrid Known Issues: Data Sources


Certain types of data sources work best for DataGrid depending on your scenario. Following are some tips which you should keep in mind when choosing a data source for your DataGrid application:

Using Linq to SQL will break sorting. In the Linq to SQL case, SQL returns Table<T> which does not implement ITypedList and therefore prevents BindingListCollectionView from correctly sorting the items. Any Linq providers that return IBindingList will see this issue. This will be fixed in an upcoming release. Until that fix is available, we recommend that you do not use a Linq to SQL (or any other provider which returns IBindingList) data source if your DataGrid requires the sorting feature. Since Linq to objects returns IEnumerable, Linq to object data sources will not break sorting.

amdiqpl 2010-03-01
  • 打赏
  • 举报
回复
我也是用linq to sql 作为dataGridView的数据源代码如下:
dataGridView1.DataSource=(from p in listUser
select p).toList();
点击dataGridView的Column Header无法实现排序,如果DataGridView的数据源是dataSet或DataTable就能很好地实现排序。这是为什么?
nanhe0065 2010-02-08
  • 打赏
  • 举报
回复
我发现如果是用LINQ TO SQL,如
var x = from c in myDataContext.TableName
select c;

this.DataContext = x;
再绑定到WPF DataGrid后就无法排序,但如果是强类型数据集通过TableAdapter.Fill()或GetData()返回的强类型DataTable绑定到DataGrid后可以点击Column Header排序,而且根本无需设置什么。

说明这两者返回的东西还是有区别的。请达人指教一下,谢谢。

huminghua 2010-02-05
  • 打赏
  • 举报
回复
设置一个属性,叫什么我就忘记啦!你自己仔细找找!
平生我自如 2010-02-05
  • 打赏
  • 举报
回复
在控件的右上角那里可以设置的吧!有个复选框叫重新排序!钩上就可以了吧

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧