Thorin Oakenshield
Thorin Oakenshield

Reputation: 14672

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

enter image description here

But the need like

enter image description here

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 .

Please help me to modify/rewrite my above code.

Thanks in advance.

Upvotes: 0

Views: 176

Answers (2)

Sanjeevakumar Hiremath
Sanjeevakumar Hiremath

Reputation: 11263

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);

Upvotes: 1

user623879
user623879

Reputation: 4142

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.

Upvotes: 0

Related Questions