how to select a ListViewItem from ListViewItemCollections using Linq in C#?
i tried on using this but it didn't work..
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..
The Take operator is used to return a given number of rows from a database table and the Skip operator skips over a specifed number of rows in a database table. I create a data context class that has tables or a stored procedure.
By default, LINQ queries return a list of objects as an anonymous type. You can also specify that a query return a list of a specific type by using the Select clause.
@CYB: select new is used when you want your query to create new instances of a certain class, instead of simply taking source items. It allows you to create instances of a completely different class, or even an anonymous class like in OP's case.
To get an enumerator of ListViewItem
, you have to cast the Items
collection of ListView:
IEnumerable<ListViewItem> lv = listview1.items.Cast<ListViewItem>();
Then, you can use LINQ with it:
var test = from xxx in lv
where xxx.text = "data 1"
select xxx;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With