How to change the checked property of ListViewItem?
I've a ListView with two columns and i'm filling the ListView using the code below
ListViewItem[] l_lvItem = Enumerable.Range(0, 10).Select(X => new ListViewItem(new String[] {X.ToString(),(X+1).ToString() })).ToArray();
listView1.Items.AddRange(l_lvItem);
Here is the output of the above code
But the need like
I've enabled the Checkboxes
property of my listView. But i cannot change the checked property of the each item using the above code.
Using for/foreach
loop i can change the property,
but just need to a simple way .
Pleas开发者_如何学Goe help me to modify/rewrite my above code.
Thanks in advance.
This is what you need.
ListViewItem[] l_lvItem = (from X in Enumerable.Range(0, 10)
select new ListViewItem(new String[] { X.ToString(), (X + 1).ToString() }) { Checked = true }).ToArray();
listView1.Items.AddRange(l_lvItem);
I don't think there is a way to change all them to checked with one function call or w/e.
You need to loop through each element and change it after you have added them all.
精彩评论