Processing of page turning for ListView Big Data Display

Source: Internet
Author: User
Display Data. Generally, there are two options: ListView and DataGrid. For the latter, the page flip function is easier to implement, so it does not seem very easy to implement the page flip function of ListView. The main difficulty is that ListView does not provide the page flip function. In addition, it is difficult to calculate how much data can be displayed on a page in a specific ListView. Because a ListView, if the data you display cannot be filled with the entire ListView, it does not look very beautiful. Today, I will give my practices on these two issues.
1. Calculate the maximum number of records displayed by ListView (one page, no scroll bar, not included in the horizontal scroll bar)
/// <Summary>
/// Obtain the maximum number of records displayed by ListView (no scroll bar)
/// </Summary>
/// <Param name = "lv"> </param>
/// <Returns> </returns>
Public int GetListViewPageRecordNum (ref ListView lv)
{
Int _ itemHeight = 0;
If (lv. Items. Count> 0)
_ ItemHeight = RectangleToClient (lv. Items [0]. Bounds). Height;
Else
{
Lv. Items. Add (new ListViewItem (new string [] {"0", "0 "}));
_ ItemHeight = RectangleToClient (lv. Items [0]. Bounds). Height;
Lv. Items. Clear ();
}
// RECT itemRect = new RECT ();
// SendMessage (lv. Handle, (int) HeaderControlMessages. HDM_GETITEMRECT, 0, ref itemRect );
Int columnHeaderHeight = 0; // itemRect. bottom-itemRect. top;
// If (columnHeaderHeight = 0)
ColumnHeaderHeight = _ itemHeight * 2; // use twice the height of the Data row as the column height
// Calculate the maximum number of records that a listview can accommodate (when the scroll bar is not displayed)
Int rnum = (lv. rectangleToClient (new Rectangle (lv. location. x, lv. location. y, lv. width, lv. height )). height-columnHeaderHeight)/_ itemHeight;
Return rnum;
}
Note: I didn't get the height of the column name (ColumnHeader) of ListView, So I replaced it with twice the Item height.

2. the maximum number of records displayed on each page of the ListView ensures that the ListView can display "full" of data. The following is a paging user control of the ListView: ListViewPager.
Attributes of ListViewPager:
CurrentPageNum -- the number of pages currently displayed
MaxPageNum -- maximum number of pages
GoPageNum -- number of pages to jump
...
ListViewPager event:
/// <Summary>
/// Previous page button event
/// </Summary>
[Category ("Pager"), Description ("Previous Page button event")]
Public event PreClickHandle PreButton_Click;
/// <Summary>
/// Button event on the first page
/// </Summary>
[Category ("Pager"), Description ("first page button event")]
Public event FirstClickHandle FirstButton_Click;
/// <Summary>
/// Next page button event
/// </Summary>
[Category ("Pager"), Description ("next page button event")]
Public event NextClickHandle NextButton_Click;
/// <Summary>
/// Button event on the last page
/// </Summary>
[Category ("Pager"), Description ("last page button event")]
Public event LastClickHandle LastButton_Click;
/// <Summary>
/// Jump to the specified page button event
/// </Summary>
[Category ("Pager"), Description ("Jump to specified page button event")]
Public event GoToHandle GoButton_Click;
Public methods provided by ListViewPager:
Public void RollBackPage ()
Public void SetCurrentPage (int page)
Public void initialize mclickfirstbutton ()
The above information is the main information of ListViewPager, and its implementation is mainly implemented in the status. The specific ListView paging Data Binding needs to be implemented by the user on the client. The specific implementation method is called, directly in the five page flip events provided. When binding data each time, you need to bind the data of the corresponding page based on the specified page of ListViewPager. At the same time, due to the change in the number of records per page or the change in the total number of records, the total number of pages may change, so you must specify the total number of pages when binding. If they are consistent, you do not need to specify them.

The following is the download of the control source code without a demo. It is mainly intended to provide you with an idea and easy to use. It will be provided after the demo.

Related Article

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.