Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a List control which about 280000 items should be added to that and then display. it takes about 4 minutes for me and my UI goes disable during the time.

how can I reduce the Delay time?

What I have tried:

pTable = new CListCtrl;
CString strtemp;
for (unsigned int i = 1; i <= size; i++)
{
    pTable->InsertItem(i, strtemp);
}
Posted
Updated 16-Jul-18 0:54am

Who will read (and scroll through) 280,000 items?

A solution would be using a virtual list control that handles only the items actually visible. See Virtual List Controls | Microsoft Docs[^].

For a non virtual list control you can (and should always even with smaller lists) disable the screen update while modifying the list:
pTable->SetRedraw(FALSE);

// Modify list here

pTable->SetRedraw(TRUE);

// Invalidate the entire list
pTable->Invalidate();
// Force painting
pTable->UpdateWindow();


[EDIT]
When knowing the number of items in advance, use SetItemCount() initially. Even when not knowing the count in advance, it might be finally faster to determine and set it.

For further improvements make the code inside the loop as fast as possible (simple). That includes avoiding any function that allocates memory in the loop. Use for example preallocated CStrings or plain text buffers defined outside the loop using the max. possible string length. If possible, avoid also any string formatting function.
[/EDIT]
 
Share this answer
 
v2
Comments
saide_a 16-Jul-18 7:07am    
it's list of 8 byte messages in 4 MB memory.
Jochen Arndt 16-Jul-18 7:22am    
The memory does not care while there is no swapping. What cares is who is reading such large lists.

Disabling redraw will speed up a lot. If that is not sufficient, you have to use a virtual list or smaller ones.
KarstenK 16-Jul-18 12:46pm    
The virtual list control is the correct solution AND only load data which needs to display. Loading all data means to load a lot of stuff which isnt displayed on the screen and is slowing down your app.

Always remember: the listcontrol isnt made for massive data, but some small snapshot for the user.
saide_a 22-Jul-18 0:08am    
Many thanks ,I used virtual list as described in this link https://www.codeproject.com/Articles/7891/Using-virtual-lists
Have you considered paging or infinite scrolling? Items may be created/retrieved in a different thread but updating a control always blocks UI thread unless the control supports some kind of virtualization. The best approach is add items by parts (for example 200 items at a time) but you should decide when to add specific part: the one approach is paging. You can also add the next batch o of items when user scrolls to the bottom (infinite scrolling).
 
Share this answer
 
Comments
saide_a 16-Jul-18 7:00am    
In My Case almost always complete scrolling is needed, only at the "open" click I want the list to update an show, and in other thread nothing related to the listctrl. what do you suggest for me?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900