Click here to Skip to main content
14,209,124 members
Rate this:
Please Sign up or sign in to 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);
Updated 16-Jul-18 0:54am
Rate this:
Please Sign up or sign in to vote.

Solution 2

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:

// Modify list here


// Invalidate the entire list
// Force painting

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.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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).
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)

Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.190617.3 | Last Updated 16 Jul 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100