如何在 C# 中使用 Linq 从 ListViewItemCollections 中选择一个 ListViewItem?
我试过用这个但是没用..
ListViewItemCollections lv = listview1.items;
var test = from xxx in lv where xxx.text = "data 1" select xxx;
test <--- now has the listviewitem with "data 1" as string value..
最佳答案
要获取 ListViewItem
的枚举器,您必须转换 ListView 的 Items
集合:
IEnumerable<ListViewItem> lv = listview1.items.Cast<ListViewItem>();
然后,您可以将 LINQ 与它一起使用:
var test = from xxx in lv
where xxx.text = "data 1"
select xxx;
关于c# - Linq 在 C# 中从 ListViewItemCollections 中选择项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6640198/