Response of Treeview to adding massive nodes

Source: Internet
Author: User

When I useProgramAdd 0.1 million nodes to the Treeview;
No matter you use. begininvoke or other multi-threaded addition methods, the following results cannot be achieved:
In this way, the Treeview can respond to a series of operations-double-click and expand .. And so on;
Is there a way to solve this problem? Is this a natural defect in the Treeview space?
I once saw someone using MFC to implement the function of adding nodes while performing a response operation!
Which one can tell me the answer?

Add Method 1:
Treenode tn;
For (INT I = 0; I <100000; I ++)
{
Tn = new treenode (I. tostring ());
This. treeview1.nodes [0]. nodes. Add (TN );
}

No doubt, the CPU usage is 100%, and the interface cannot respond

Method 2:

Private void form1_doubleclick (Object sender, system. eventargs E)
{
 
This. treeview1.begininvoke (New treeinvoke (this. updatetreeview ));

}

Private void updatetreeview ()
{
System. datetime dt = datetime. now;
Treenode tn;
// This. treeview1.beginupdate ();
For (INT I = 0; I <100000; I ++)
{
Tn = new treenode (I. tostring ());
This. treeview1.nodes [0]. nodes. Add (TN );
If (I % 100 = 0)
{
System. Threading. thread. Sleep (100 );
}
}

// This. treeview1.endupdate ();
System. timespan Ts = datetime. Now-dT;
MessageBox. Show (TS. tostring ());

}

CPU utilization is not high, but the interface cannot respond

Method 3:
Private void form1_doubleclick (Object sender, system. eventargs E)
{
System. datetime dt = datetime. now;
For (INT I = 0; I <10000; I ++)
{
This. treeview1.begininvoke (New treeinvoke (this. updatetreeview ));
System. Threading. thread. Sleep (10000 );
}
System. timespan Ts = datetime. Now-dT;
MessageBox. Show (TS. tostring ());
}

Private void updatetreeview ()
{

Treenode tn;
// This. treeview1.beginupdate ();
For (INT I = 0; I <10; I ++)
{
Tn = new treenode (I. tostring ());
This. treeview1.nodes [0]. nodes. Add (TN );
}

// This. treeview1.endupdate ();

}

Result approximation method 2;

Is there any way to use Treeview to achieve my goal without changing the content organization method (non-hierarchical display?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.