c# - Linq 在 C# 中从 ListViewItemCollections 中选择项目

标签 c# linq

如何在 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/

相关文章:

c# - 如何设置哪个表格先出现

c# - 从动态对象列表中删除对象

c# - 从 xml 文件生成 POCO 对象

c# - 如果列表为空,则添加默认字符串

c# - 如何使用 Linq 确定 List<T> 中的所有对象是否具有相同的属性值

c# - 使用 iTextSharp 获取包含在指定区域中的文本事件

c# - 嵌套 Lambda 表达式

c# - 使用 xslt 从 rss 文件创建 html 列表

c# - Entity Framework : LINQ query generates different SQL between local execution and server execution

c# - LINQ FirstOrDefault 与 Where(...).FirstOrDefault 之间的区别?