LINQ on ListView.Items (ListViewItemCollection)
-
I wold like to check all items in a ListView. Can I do that without a foreach (...) using LINQ? I want to do something like this:
mylistView.Items.All().Check = true;
_____________________________ ...and justice for all APe
-
I wold like to check all items in a ListView. Can I do that without a foreach (...) using LINQ? I want to do something like this:
mylistView.Items.All().Check = true;
_____________________________ ...and justice for all APe
You could do it like:
listView1.Items.OfType<ListViewItem>().ToList().ForEach(x => x.Checked = true);
It's not that elegant as there isn't a Enumerable.ForEach there's a static one for arrays, and one built in for List though. Edit: You could use OfType().All() however it takes a predicate and returns those matching it. Changing the input could get confusing and if you change a property that's not a bool it would get messy.modified on Sunday, April 6, 2008 11:16 PM