如何在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..
Run Code Online (Sandbox Code Playgroud)
Hom*_*mam 26
要获取枚举器ListViewItem,必须转换ItemsListView 的集合:
IEnumerable<ListViewItem> lv = listview1.items.Cast<ListViewItem>();
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用LINQ:
var test = from xxx in lv
where xxx.text = "data 1"
select xxx;
Run Code Online (Sandbox Code Playgroud)
ListViewItemCollections lv = listview1.items;
var test = from ListViewItem xxx in lv where xxx.text == "data 1" select xxx;
Run Code Online (Sandbox Code Playgroud)
要么
listview1.items.Cast<ListViewItem>().Where(i => i.text == "date 1");
Run Code Online (Sandbox Code Playgroud)