Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a tree control. MFC Project.

When that tree control has too many tree items (more than 310,000 items),
just one line - SetRedraw(TRUE);
that's too slow. (about 2 sec)

-----------------------------
m_treeCtrl.SetRedraw(FALSE);
// do nothing
m_treeCtrl.SetRedraw(TRUE);
-----------------------------

SetRedraw(FALSE) - no problem


I'm really curious about why so slow, and how can i handle it.
Does anyone know this problem?

What I have tried:

m_treeCtrl.SetRedraw(FALSE);
// do nothing
m_treeCtrl.SetRedraw(TRUE);
Posted
Updated 13-Jan-20 5:04am
Comments
KarstenK 13-Jan-20 6:15am    
re-drawing 310.000 items isnt a good idea. It not only takes time, but is waisting lots of energy. :-O

Because setting Redraw to TRUE causes the contents of the control to be re-evaluated and repainted.

And if your tree control contains 300,000+ items, your UI is badly flawed. Never present users with that number of times, it's pretty much impossible to locate the one item they are interested in in a flood of other things. Either each individual item will be buried 100 branches down or each branch will contain a thousand items - and either way it's very arduous and time consuming to find a particular item. It may be easy for you do code, but it's a PITA for users to use.

Think about it: if you went to eBay and had to access everything for sale via a tree, how quickly would you be browsing Amazon instead?

Your users will hate it, your app, and you - and I'd uninstall it with extreme prejudice and be demanding my money back PDQ.

Never present more than 100 items or so at a time, and provide filtering, searching, and sorting options so they can locate what they want quickly and easily. And it's quicker to display as well!
 
Share this answer
 
Comments
CPallini 13-Jan-20 5:39am    
5.
lord2sh 13-Jan-20 20:29pm    
Thank you so much. It helped me a lot. I need to change the way i think. :)
OriginalGriff 14-Jan-20 1:58am    
You're welcome!
Mr. Griff gave the reasons for the problem. Sometimes it is rather difficult to work around so I use the following little class to help :
C++
///////////////////////////////////////////////////////////////////////////////
// This excursion class will lock windows update on construction and
// unlock windows update on destruction.

class LockWinUpdate
{
public:
    LockWinUpdate( CWnd *pw )
    {
        m_pWnd = pw;
        m_pWnd->LockWindowUpdate();
    }

    virtual ~LockWinUpdate()
    {
        m_pWnd->UnlockWindowUpdate();
    }

protected:
    CWnd * m_pWnd { nullptr };
};
To use this, create an instance where updates should be locked and set the scoping of the object such that the object is deleted when you want updates to be unlocked. Something like this :
C++
{
    LockWinUpdate lockem( this );

    // update the window here

} // object has been destroyed so updates will resume
 
Share this answer
 
Comments
lord2sh 13-Jan-20 20:29pm    
Thank you so much. I'm using SetRedraw(TRUE/FALSE) like the way you show me. But I didn't know about LockWindowUpdate() function. Instead of SetRedraw, Using LockWindowUpdate is more faster. that's really fast and useful. it works perfect for me. I really appreciate your help

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