Very long MFC CListCtrl lists ?

I want to use CListCtrl list with many items (e.g. more then 30000), but it is impossible or very slow. Is there any solution for this problem? I will accept solutions with some other control, but with similar functionality.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Use Virtual list control instead
U will find relevent info on microsoft web site
You can turn the list control into a virtual list control. This is a new style implemented with the common controls version included with Internet Explorer 4.0 (among other places). It is also included with Visual C++ 6.0.
You simply have to handle two additional messages. On to provide feedback for a certain item requested by the control, and the other to manage a cache, in order to speed up things. YOu can find more information in, where they also have example code.
I can assure you the problem is not with the list control itself, simply your usage of it.

The most efficient use of a list control is via the Text Callback mechanism:

Using this mechanism in release code on a 500 MHz PII with 128M RAM and a fast Video Card  I can fill the list with 100,000 rows in less than 7 seconds, this is about 15,000 rows per second.  So for your 30,000 rows this would be about 2 seconds.

Note also, that I am using a relatively inefficient method for formatting the text on each row.  The speed could be dramatically improved by doing something more sensible, I suspect that you could fill a list ctrl with 100,000 entries using something 'smarter' than sprintf in less than 1 second.

void CListDlg::OnGetdispinfoList1(NMHDR* pNMHDR, LRESULT* pResult)

      sprintf(pDispInfo->item.pszText, "Text line %d", pDispInfo->item.iItem);


      *pResult = 0;

void CListDlg::FillList()
      CWaitCursor o;

      for(int i = 0; i < 100000; i++)
            m_List.InsertItem(i, LPSTR_TEXTCALLBACK );


void CListDlg::OnOK()
See the APIBROW.ZIP sample at . (Note that my webpage will soon move to )

This sample is described at great length in my book.

..B ekiM

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.