Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to select all listview items?

Tags:

c#

winforms

how to select all listview items ?

like image 502
pedram Avatar asked Aug 04 '10 12:08

pedram


2 Answers

There is already an accepted answer for this but I use something similar to this:

lv.BeginUpdate();
List<ListViewItem> items = (from i in lv.Items).ToList;
items.ForEach(i => i.Selected == true);
lv.EndUpdate();

It seems to run much faster if there's several thousand items. Also, since we're using BeginUpdate() and EndUpdate(), the ListView control doesn't update after selecting each item.

like image 132
Jason Avatar answered Oct 14 '22 12:10

Jason


Just pass your listview and checkstate to the function.

public void CheckAllItems(ListView lvw, bool check)
{
    lvw.Items.OfType<ListViewItem>().ToList().ForEach(item => item.Checked = check);
}
like image 23
Chandan Kumar Avatar answered Oct 14 '22 12:10

Chandan Kumar