Click here to Skip to main content
15,881,719 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I can't figure out how to programmatically select all items in a huge listview. It seems like it should be relatively easy, like "ListView.SelectAll()" or "ListView.Items.SelectAll()", but that doesn't appear to be the case. I do not find the "select all" command. STRG+A does not work either and I can't call it therefore.
Any better ideas than a flickering slow loop through all the items which I tried?

Note: I seek an inbuild command for this, I might have overlooked the rite function.

What I have tried:

I tried to loop through each element with foreach loop and set the property for each element separatly. it wasn't working fully, the listView flickered horrible and it took ages for 50000 elements to be selected. I found some similar questions in the internet, but no answers provided. I seek a better answer than my solution, an inbuild command or something alike as pure C#. Does somebody know a command?
VB6 had a "SelectAll" property and it selected up to 100K elements in a second. What I have to do to get this functionality in my C# program?
Posted
Updated 29-Apr-16 8:55am

1 solution

First, I have to say, if you're loading 50000+ items into a ListView, you have serious design issues. You might want to consider some kind of paging.

Ok, so, try adding each item in your collection to the listView's SelectItem collection.. Something like

foreach(var item in myItems)
{
myListView.SelectedItems.Add(item);
}
 
Share this answer
 
v2
Comments
Patrice T 30-Apr-16 11:10am    
"wasn't working" is not informative !
Kevin Marois 29-Apr-16 14:59pm    
The problem is that you're loading WAY too many items. Try loading 100 at a time. Handle the Scrolled event to load the next 100.
Kevin Marois 29-Apr-16 15:00pm    
Have you tried using a Grid instead of a ListView?
Kevin Marois 29-Apr-16 16:51pm    
Don't know what STRG-A means.. The problem here is that you're loading way too many items. The list isn't designed for this. You need to rethink your design. As I said before, consider paging.
Kevin Marois 29-Apr-16 17:21pm    
Try CTRL-A, which is the standard Windows shortcut for Select All, but it wouldnt surprise me if it either didn't work or it was really slow.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900