Type list of selected items in a wpf datagrid

陌路散爱 提交于 2019-12-03 13:48:38

The type of the SelectedItems property is the non-generic IList. You can't simply cast that to the generic IList<T>.

You could however use LINQ to get an IEnumerable<x> or a List<x>.

using System.Linq;

IList list = obj as IList;
IEnumerable<x> SelectedItemsList = list.Cast<x>();
// or 
List<x> SelectedItemsList = list.Cast<x>().ToList();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!