SelectedIndexChanged event and the list view control.

R

Robin Tucker

When volume testing my application I have noticed a big problem with
listview controls populated with large numbers of items (ok, when I say
large, I mean 3 or 4 hundred items, so in the grand scheme of things, quick
small!).

The problem is that I am using a multiple selection list view and if the
user selects item 1 and then Shift-selects to the end of the list, the
selectedindex event is fired around 400 times! This means that any events I
fire or things I do in the handler get executed once for each new selected
item.

What I want to do is detect a selection change in the round, not on an
individual item basis, so I can fire my event just once when a new "multiple
selection" is made.

How can I do this?
 
E

EricJ

i know this is a bit strange but i don't c another option right now (not
tested but the idea should work)

i don't think you can pass the selectedindex(changed)
but you can do a control in there and don't execute your code if you don't
need to

on the keydown of the listbox check the shift
if it is shift set a boolean to false
in your selectedindexchanged only do your code if the boolean is true
on the keyup test again for shift and set the boolean back to true

keep in mind if you manually fill large listboxes and combos set the sorted
to false before you start filling and back to true when you are done. (if
you sort every time as you are adding +5k items it gets slow 2)

hope it helps a bit

eric
 
R

Robin Tucker

Ok, I solved my own problem. What I did was setup a flag called
"m_bSelectionChanged", set to false by default. In the SelectionChanged
event for the listview, I just have "m_bSelectionChanged = true". Now I
also handle the MouseUp event and in the MouseUp event I write "if
m_bSelectionChanged then ...... m_bSelectionChanged = false.... end if" and
voilla, it works no more drag :)
 

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