![]() |
|
By Alexander Shargin, .
QA: How to add a lot of items to the ListView control?QuestionI have to add many items to a list view in my program. But the process is VERY slow. How can I speed things up? AnswerUse virtual list viewThe only way to eliminate time used to add items to a list box is not to add them at all. This is possible with virtual list view (i. e. list view with LVS_OWNERDATA style set). Virtual list view does not store information on its items. Instead it stores the number of items in the list. When virtual list view is redrawn it requests only the information on the items actually visible on the screen. To provide this information you must handle LVN_GETDISPINFO notification write data to LV_DISPINFO structure provided to notification handler. To make your list view virtual follow these steps.
Use SetRedraw methodIf it's impossible to use virtual list view for some reason, there is not much you can do. Copying item data to list view's internal structures takes time. You can do nothing about it. But you can eliminate time used to redraw the list view over and over again after each item is added. To do this call CListCtrl::SetRedraw method to turn off list redrawing, then add all items to the list and use CListCtrl::SetRedraw method again, e. g.: This approach can speed up your program 2-4 times but do not expect much if the number of items is really big. DiscussDiscuss this article. Here you can write your comments and read comments of other developers. |
|||||||||||||||||||||