Selecting all items in a listview

B

Bry

I know you can select a single item in a list view using the following
code

listView.Items[index].Selected = true;

Is it possible to do this for all items in the listView control without
using a loop?

Thanks.
 
V

VJ

Not that I know.. but you could extend and write your own ListView control
with a Method that will do this. In the Method you will essentially write a
for loop that will select all items..

VJ
 
G

Guest

Tim Wilson said:
You could loop through and select each item. However, a method that is a
little faster, especially when you've got a lot of items, is to send the
ListView some key messages. For example...

this.listView1.Focus();
SendKeys.Send("{HOME}");
SendKeys.Send("+{END}");

You might need to send a Space after the {HOME} to make it work. I'm using
an oaklistview (win32 control pinvoked from user32.dll with support for
images anywhere in the list), and haven't tested with a standard listview,
but in my case without the space to select the first item the 2nd keystroke
sent was processed from the item selected before sending the keys.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top