How to (quickly) populate CListCtrl in C ++ (MFC)?

In my application, I have several CListCtrl tables. I populate / update them with data from an array with a for loop. Inside the loop, I have to make some changes to the way I display the values, so data binding in any way is not possible at all.

The real problem is the time it takes to populate the table as it is redrawn row by row. If I turn the control invisible when it is full, and again make it visible when the cycle is complete, the whole method will be much faster!

Now I'm looking for a way to stop control from repainting to full. Or any other way to speed up the process.

+6
c ++ mfc clistctrl
source share
2 answers

Take a look at the SetRedraw method. Call SetRedraw (FALSE) before filling in the SetRedraw (TRUE) control.

I would also recommend using RAII for this:

class CFreezeRedraw { public: CFreezeRedraw(CWnd & wnd) : m_Wnd(wnd) { m_Wnd.SetRedraw(FALSE); } ~CFreezeRedraw() { m_Wnd.SetRedraw(TRUE); } private: CWnd & m_Wnd; }; 

Then use as:

 CFreezeRedraw freezeRedraw(myListCtrl); //... populate control ... 

You can create an artificial block around the code in which you populate the list control if you want freezeRedraw to freezeRedraw out of scope to the end of the function.

+18
source share

If you have many entries, it may be more convenient to use the virtual list style ( LVS_OWNERDATA ). You can find more information here .

+6
source share

All Articles