【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"之外,还要编写代码吗?
...全文
455 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
  • 打赏
  • 举报
回复
在控件的右上角那里可以设置的吧!有个复选框叫重新排序!钩上就可以了吧
内容概要:本文围绕“考虑多类型资源的数据中心园区供电协调规划”展开研究,重点探讨了源-荷-储多元协同下的供电规划与运行一体化优化问题。研究融合可再生能源、算力负载及时空调度等因素,提出基于多元宇宙优化算法的求解方法,实现对数据中心园区容量配置与日调度的协同优化。通过构建多场景概率模型与柔性变电站型园区架构,兼顾供电可靠性与算力柔性,提升系统运行效率与能源利用率。该资源配套完整的Matlab代码实现,涵盖多元宇宙算法求解、场景生成与削减、优化调度建模等关键环节,适用于科研复现与工程仿真。; 适合人群:具备一定电力系统、优化算法基础,从事新能源、数据中心能源管理、智能调度等相关领域研究的研发人员及高校研究生。; 使用场景及目标:①应用于数据中心园区含高比例可再生能源的供电系统规划;②支撑科研工作中对多元宇宙优化算法、场景概率建模、源网荷储协同调度等技术的复现与改进;③服务于微电网、综合能源系统等领域的优化调度算法开发与仿真验证。; 阅读建议:建议结合文中提供的Matlab代码与完整资源包进行同步实践,重点关注多元宇宙优化算法的实现流程与调度模型的数学建模细节,宜在掌握基本优化理论基础上开展学习与拓展。

111,129

社区成员

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

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

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