tags:

views:

507

answers:

2

Hello

in my application I have a few CListCtrl tables. I fill/refresh them with data from an array with a for-loop. Inside the loop I have to make some adjustments on how I display the values so data binding in any way is not possible at all.

The real problem is the time it takes to fill the table since it is redrawn row by row. If I turn the control invisible while it is filled and make it visible again when the loop is done the whole method is a lot faster!

Now I am looking for a way to stop the control from repainting until it is completely filled. Or any other way to speed things up.

+9  A: 

Look into the method SetRedraw. Call SetRedraw(FALSE) before starting to fill the control, SetRedraw(TRUE) when finished.

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 like:

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

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

Nick Meyer
+4  A: 

If you have a lot of records may be it is more appropriate to use virtual list style (LVS_OWNERDATA). You could find more information here.

Kirill V. Lyadvinsky