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.