Solved

Populating ListView takes forever

Posted on 2003-11-30
4
406 Views
Last Modified: 2010-08-05
I have a listView that I am adding a few thousand items to.  The first time I do it, it takes a few seconds, which is fine.  

When I reload the data, it takes too long when adding the items to the listView.  

I have sorters that sort based on columns when the headers are clicked.  I am removing the sorters from the the handlers, for the column clicking and then calling items.Clear() and adding all of the thousand or so items back in.  I don't know that this is doing anything, however.  It was taking 50 seconds reload.  Then I removed the sorters and called BeginUpdate() and EndUpdate().  Now it takes about 9 seconds.  Is there anything else I can do to speed this up?
0
Comment
Question by:jjacksn
  • 2
4 Comments
 
LVL 4

Expert Comment

by:MrGhost
Comment Utility
Why don't you just debug your application, so you can see which part of your code is slow?
0
 
LVL 20

Accepted Solution

by:
TheAvenger earned 250 total points
Comment Utility
BeginUpdate and EndUpdate are actually what you could do to speed up (you did it already). Now try calling the methods in this order:

BeginUpdate()
items.Clear()
remove sorters
add items
re-add sorters (if needed, but this can also slow down)
EndUpdate

The way you do it (first remove sorters, then clear the items) could probably ask the view to resort the items in the default sorting they have which takes some time.

If you call all these methods in this order, I think this is the best you can get from the speed of the list view with so many items in it.
0
 
LVL 5

Author Comment

by:jjacksn
Comment Utility
Mr Ghost, I'm actually away from my dev studio, and I can't replicate the behavoir until I am back next week.

If I hide the form while I am doing this, would this help?  I thought beginUpdate dold the control not to redraw itself?  When it is quick when the program is first loading, the control is not visible.
0
 
LVL 20

Expert Comment

by:TheAvenger
Comment Utility
No, don't hide the form, it will not help. The first time you load the form, you con't have the sorters sorting anything. That's why I think the sorters are the problem...
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now