?
Solved

Populating ListView takes forever

Posted on 2003-11-30
4
Medium Priority
?
459 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:MrGhost
ID: 9848883
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 1000 total points
ID: 9848974
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
ID: 9851201
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
ID: 9851264
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

762 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