[英]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 我有一个包含两列的ListView,我使用下面的代码填充ListView
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. 我已启用listView的
Checkboxes
属性。 But i cannot change the checked property of the each item using the above code. 但是我无法使用上述代码更改每个项目的选中属性。
Using for/foreach
loop i can change the property, 使用
for/foreach
循环,我可以更改属性,
but just need to a simple way . 但是只需要一个简单的方法。
Please 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. 我不认为有一种方法可以将所有这些更改为通过一个函数调用或w / e进行检查。
You need to loop through each element and change it after you have added them all. 添加完所有元素后,您需要遍历每个元素并对其进行更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.