UnSelect a Modifier Key For ListView SelectAll

  • Thread starter Thread starter NvrBst
  • Start date Start date
N

NvrBst

I have a ListView (VirtualMode) and I want to implement a SelectAll.

--1st Atempt--
The standard for loop takes way to long: "for(int i = 0; i <
listView1.VirtualListSize - 1; i++)
listView1.SelectedIndices.Add(i);". I've tried wrapping the above
statment in a "listView1.SuspendLayout() /
listView1.ResumeLayout(false)" but it didn't help. 3000 Elements
takes about 15 seconds to select with this.

--2nd Atempt--
I then tried "SendKeys.Send("{END}+{HOME}");" which works fast,
however, it only works when I click the menu item; it has a HotKey
"Ctrl-A", and when I use that what my listView is processing is the
"Ctrl-End, Shift-Home", which doesn't select all element (ctrl-end
moves the scroll bar). 3000 Elements takes about 1 seconds to select
with this.

--3rd Atempt--
I see a
"System.Windows.Forms.ListView.ReflectMessage(listView1.Handle, ?
Message?);" which might be what I want to use but think it might just
act the same as SendKeys.Send(...)...


--Questions--
Would "3rd Atempt" be the way to send the "END, SHIFT-HOME" and bypass
the ctrl key? Or it'd end up with same result as SendKeys?

Is there a way to send the "ctrl up" message, eventhough the user may
still be holding it down, before/during the "SendKeys.Send"?

Is there an easier way to add all the elements to the SelectedIndices
at once (IE like AddRange)? Or a better way to select all elements,
or something I can wrap around the "for loop ->
SelectedIndices.Add(...)" so that it doesn't process whatever it's
processing?


Currently I just add a "Thread.Sleep(500);" before the
"SendKeys.Send", which works okay, however, would like to update it
incase the user is holding down the ctrl key for a long time. Thanks.
 
I have a ListView (VirtualMode) and I want to implement a SelectAll.

--1st Atempt--
The standard for loop takes way to long: "for(int i = 0; i <
listView1.VirtualListSize - 1; i++)
listView1.SelectedIndices.Add(i);".  I've tried wrapping the above
statment in a "listView1.SuspendLayout() /
listView1.ResumeLayout(false)" but it didn't help.  3000 Elements
takes about 15 seconds to select with this.

--2nd Atempt--
I then tried "SendKeys.Send("{END}+{HOME}");" which works fast,
however, it only works when I click the menu item; it has a HotKey
"Ctrl-A", and when I use that what my listView is processing is the
"Ctrl-End, Shift-Home", which doesn't select all element (ctrl-end
moves the scroll bar).  3000 Elements takes about 1 seconds to select
with this.

--3rd Atempt--
I see a
"System.Windows.Forms.ListView.ReflectMessage(listView1.Handle, ?
Message?);" which might be what I want to use but think it might just
act the same as SendKeys.Send(...)...

--Questions--
Would "3rd Atempt" be the way to send the "END, SHIFT-HOME" and bypass
the ctrl key?  Or it'd end up with same result as SendKeys?

Is there a way to send the "ctrl up" message, eventhough the user may
still be holding it down, before/during the "SendKeys.Send"?

Is there an easier way to add all the elements to the SelectedIndices
at once (IE like AddRange)?  Or a better way to select all elements,
or something I can wrap around the "for loop ->
SelectedIndices.Add(...)" so that it doesn't process whatever it's
processing?

Currently I just add a "Thread.Sleep(500);" before the
"SendKeys.Send", which works okay, however, would like to update it
incase the user is holding down the ctrl key for a long time.  Thanks.

Encase someone else runs into a similar problem, I was able to remove
the "Thread.Sleep(...)" delay by changing the "SendKeys.Send("{END}+
{HOME}");" to the following:


listView1.Items[lastElement].Selected = true;
SendKeys.Send("+{HOME}");


This way even if the ctrl key is still being held down, it'll select
all the element. However, if you select an element, and then hit the
"ctrl-a" function quickly after, it sometimes re-selects the 1st
element after it selects all (thus unselected all the elements), which
I can't explain. It doesn't happen to often though. I think if I
could change it to something like

listView1.Items[lastElement].Selected = true;
SendKeys.Send("+"); //ShiftKey Down
listView1.Items[0].Selected = true;
//ShiftKey Up

I'd like it best (it keep the user where they are origionally, and
probably fix the problem I labeled before). Is there an simple/fast
way to send a ShiftKey Down / ShiftKey Up message? I couldn't find
how to do it with SendKeys.

Thanks
 

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

Back
Top