inserting Items in Listview too slow

  • Thread starter Stephan Zaubzer
  • Start date
S

Stephan Zaubzer

Hi,
I need to insert thousands (up to 50000) of items taken from a Database
into a ListView control. But this happens to be too slow. Constructing
all the items and putting them into an array is pretty fast (split
second). But when adding the Items with
ListView.Items.AddRange(itemArray) it takes 10 seconds for 37000 items
on my machine (Athlon XP 1700+ 768MB Ram).
Is there a way to speed the task up, or does anyone know an alternative
widget which has basically the same functionality (multi column view
with sorting capabilities for each column).
Regards
Stephan
 
T

Tom Dacon

Stephan, putting that many items into list-type controls is generally
considered to be a bad idea for a variety of reasons, some due to
performance both on the database and on the control, some due to the
awkwardness of the user interface from the perspective of the person running
the application. You're seeing the worst part of the performance equation.
You should consider developing a paging scheme so that you can load into the
control a more reasonable number of items. You might go ahead and cache the
dataset with all the records, and then page your way through it with forward
and back buttons on the page or form.

HTH,
Tom Dacon
Dacon Software Consulting
 
A

Andrew Robinson

Wrap your insert logic inside of a BeginUpdate and End Update method:

listView1.BeginUpdate();

// insert rows here

listView1.EndUpdate();
 

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