如何从datagrid中获取排序的itemssource

如何从datagrid中获取排序的itemssource

本文介绍了如何从datagrid中获取排序的itemssource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个列的网格,用户可以根据任何列进行排序。数据,绑定网格是一个自定义实体的集合。我在屏幕上有一个打印按钮,点击这个按钮我需要做一个自定义打印。打印必须按照网格中显示的顺序显示数据(附带数据)



有没有办法直接获取排序的数据源,而不是排序数据源排序事件?



感谢
Pankaj

解决方案

是的, 。在WPF中,始终有一个 CollectionView 被绑定,从不集合本身。如果您不自己指定集合视图,则使用默认集合视图。您可以访问此默认集合视图,如下所示:

  CollectionViewSource.GetDefaultView(yourCollectionOfCustomEntities); 

这是采用所有排序和过滤应用的网格所示的集合视图。 >

I have a grid with multiple columns and users can sort based on any column. Data, which is bound the grid is a collection of custom entity. I have a print button on the screen and on click of this button I need to do a custom print. Print must show the data in the same order as displayed in the grid (with additional data)

Is there any way to directly get the sorted datasource instead of sorting the datasource in the sorting event?

ThanksPankaj

解决方案

Yes, there is. In WPF, always a CollectionView is bound, never the collection itself. If you don't specify a collection view yourself, a default one is used. You can access this default collection view like this:

CollectionViewSource.GetDefaultView(yourCollectionOfCustomEntities);

This is the collection view as shown by the grid with all the sorting and filtering applied.

这篇关于如何从datagrid中获取排序的itemssource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 00:12