CollectionViewSource with Sort get sorted Items

主宰稳场 提交于 2019-12-10 17:55:50

问题


I have a datagrid which has as source CollectionViewSource with custom sorting and I need to get sorted items collection as can be seen in datagrid. I can get sorted description and sort source collection, but I need this collection many time.

Is there some way how to get sorted collection which enable indexation (item[index])?


回答1:


The CollectionViewSource's View property returns a sorted ICollectionView. Since that is an IEnumerable, you could use Linq to create a List from it, which can be accessed by index:

// using System.Linq;

var list = collectionView.View.Cast<object>().ToList();
var firstItem = list[0];


来源:https://stackoverflow.com/questions/14199049/collectionviewsource-with-sort-get-sorted-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!