在 WPF DataGrid 中保留用户定义的排序顺序
我有一个 WPF DataGrid,其中填充了 DataSet 中的数据。我将 CanUserSortColumns
设置为 true。
网格刷新时是否可以保留用户指定的排序? 选择的项目
object selectedItem = dgInvoiceHeads.SelectedItem;
我让它保留在刷新发生之前
dgInvoiceHeads.SelectedItem = selectedItem;
,然后在刷新发生之后放置。
但我似乎无法让它保留指定的排序。
I have a WPF DataGrid that is populated with data from DataSet. I have CanUserSortColumns
set to true.
Is it possible to retain the sorting that the user specified when the grid is refreshed? I have it retaining the item that was selected using
object selectedItem = dgInvoiceHeads.SelectedItem;
before the refresh takes place and then placing
dgInvoiceHeads.SelectedItem = selectedItem;
after the refresh takes place.
But I can't seem to get it to retain the specified sort.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否尝试过获取数据集的集合视图?
这将为您提供当前排序描述的数组。然后,您可以坚持这些,并在下一次应用它们,如下
希望它有帮助。
Have you tried getting the collectionview for the dataset?
This will give you an array of the current sortdescriptions. You can then persist these, and the next time round apply them as follows
Hope it helps.
以下代码是从此 论坛帖子,它展示了如何获取排序描述和列信息并恢复它。
The following code was pulled from this forum post and it shows how to obtain the sort descriptions and column information and restore it.
我的一位同事想出了这个办法。它似乎工作正常。唯一的问题是我认为 DataGrid 中的列标题需要与数据库中的列标题相同。
华泰
One of my colleagues came up with this. It seems to be working correctly. The only thing is I think the column headers need to be the same in the DataGrid as they are in the DB.
HTH