List box, quickly removing many items

  • Thread starter Thread starter Jeremy Owens-Boggs
  • Start date Start date
J

Jeremy Owens-Boggs

We are trying to implement a dual list box selection where you have two list
boxes, You highlight items in the right side list box, click a button and
this moves those items over to the left hand list box. The problem is that
if there are many items selected (thousands), then removing the items from
the right side list box takes for ever because we are removing them one at a
time, which causes the listbox to re-index everything before we remove the
next one. Adding the items using AddRange works very quickly. Does anyone
have any suggestions for quickly removing items from a listbox?
 
This is what the CheckedListBox is for.
Have you tried to Clear the list and call AddRange minus the items you
intend to remove?

Otherwise, I'm sure there's some unmanaged code for this.

HTH;
Eric Cadwell
http://www.origincontrols.com
 
Jeremy,
In addition to Eric's comments.

Have you considered putting ListBox.BeginUpdate & ListBox.EndUpdate around
the code that removes the items?

The help only mentions Add with BeginUpdate, however I would expect it to
work with Remove as equally well...

Hope this helps
Jay
 
Thank you for your input. Using the BeginUpdate and EndUpdate do not speed
up the remove operation, they did remove the anoying 'flicker' when moving
the items. I like the idea of moving to a checked listbox, the big problem
is the sheer number of items in the list box, if it has to reindex each time
an item is removed, it is just going to take to long.
 
Back
Top