• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 470
  • Last Modified:

Populating ListView takes forever

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
jjacksn
Asked:
jjacksn
  • 2
1 Solution
 
MrGhostCommented:
Why don't you just debug your application, so you can see which part of your code is slow?
0
 
TheAvengerCommented:
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
 
jjacksnAuthor Commented:
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
 
TheAvengerCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now