General implementation of. NET deferred loading

Source: Internet
Author: User
Tags implement interface
Load

This article briefly describes the implementation of deferred loading in common controls.

The first time when the interface is displayed, load
The simplest delay load can load data through the first display of the control, for example, you have a lot of tabs that only load data when the user switches to the page sign.
Provides a setvisiblecore virtual method in. NET control, which is deferred loading when the detection value is true and the first time the method is called. But I do not recommend this method, because you have a better place.
-If your control inherits from form or UserControl, it is recommended to overload the onload;
-If you inherit from control, you can overload Oncreatecontrol.
The following are examples of deferred loading data:
public class Mytabpage:tabpage {
protected override void Oncreatecontrol () {
Base. Oncreatecontrol ();

String OldText = this. Text;
This. Text = "Loading ...";

TODO: Call the method that loads the data here

This. Text = OldText;
}
}
Second, the tree control is loaded on the first expansion
TreeView because all nodes are not inherited from control, you cannot use the above method, but the TreeView provides a Onbeforeexpand virtual method, the easiest way is to add a tag that is already loaded in the node you intend to implement deferred loading, Detects this tag the first time it is expanded.
You must keep in mind that your deferred load node cannot receive this event at the root location.

Third, delay loading in the table.
In Windows programs, some use paging to implement deferred loading, but the user experience in this way is very bad. If you want to still use the scroll bar, you can implement the Ibindlist interface, the internal holding a list of data IDs, when the table to query the data to the database loading data, usually the table control can work well.
But here's a place to be aware, for example, when the user presses the PageDown, the table control Continuous call to get the data method, if each request to call the database, will be very low performance, should let your program "foresee" to probably read the next 50 data, so a one-time read 50 more can be.
This approach has no way of meeting table sorting.

The above is the general technology of delay loading technology, if you have a better way, please advise.



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.