Devexpress for WPF grid paging

Source: Internet
Author: User

Devexpress for WPF did not find a paging control, the list of data too much, not paging is certainly not possible, so wrote a.

 

It feels good. Here to share with you

Idea: First create a custom control, control the paging effect and so on. The core position is the interaction of the paging information with the grid, which is done using the event delegate.

Pagination control to make this effect, relatively rough, there is time to update later.

The interface code will not be uploaded.

Backstage code for everyone to see:

  PublicDataPager () {InitializeComponent (); Cbopagesize.selectionchanged+=cbopagesize_selectionchanged; }         Public Delegate voidBacktocallback (intStartintNumref intcount);  Public EventBacktocallback onpagegetlist;  Public intPageIndex =1;  Public intnum = -;  Public intPageCount =1;  Public intcount; voidCbopagesize_selectionchanged (Objectsender, SelectionChangedEventArgs e) {            Try{ComboBoxItem CBB= Cbopagesize.selecteditem asComboBoxItem; Num=Convert.ToInt32 (CBB.                Content); intIend = count% num = =0? Count/num:count/num +1; PageIndex=Convert.ToInt32 (Txtjumppage.text); if(PageIndex >iend) {PageIndex=iend; } dgvlistbind (PageIndex, num,refcount);            Imgcontrol (PageIndex, Count); }            Catch(Exception ex) {}}Private voidDgvlistbind (intPageIndex,intNumref intcount) {            if(Onpagegetlist! =NULL)            {                intStart = (PageIndex-1) *num; Onpagegetlist (Start, num,refcount); if(Count = =0) {lblpagecount.content="1"; Lbltotal.content=count.                ToString (); }                Else{lblpagecount.content= (count% num = =0? Count/num:count/num +1).                    ToString (); Lbltotal.content=count.                ToString (); }            }        }        Private voidImgcontrol (intPageIndex,intPageCount) {PageCount= Pagecount/num = =0? Pagecount/num: (pagecount/num) +1; if(PageIndex <=1&& PageCount <=1) {btnfirst.isenabled=false; Btnleft.isenabled=false; Btnright.isenabled=false; Btnlast.isenabled=false; }            Else if(PageIndex = =1&& PageCount >1) {btnfirst.isenabled=false; Btnleft.isenabled=false; Btnright.isenabled=true; Btnlast.isenabled=true; }            Else if(PageIndex >1&& PageIndex <PageCount) {btnfirst.isenabled=true; Btnleft.isenabled=true; Btnright.isenabled=true; Btnlast.isenabled=true; }            Else if(PageIndex >1&& PageIndex = =PageCount) {btnfirst.isenabled=true; Btnleft.isenabled=true; Btnright.isenabled=false; Btnlast.isenabled=false; }        }         Public voidBtnfirst_click (Objectsender, RoutedEventArgs e) {PageIndex=1; Txtjumppage.text="1"; Num=Convert.ToInt32 (Cbopagesize.text); Dgvlistbind (PageIndex, num,refcount);        Imgcontrol (PageIndex, Count); }        Private voidBtnleft_click (Objectsender, RoutedEventArgs e) {PageIndex-=1; Txtjumppage.text=pageindex.tostring (); Num=Convert.ToInt32 (Cbopagesize.text); Dgvlistbind (PageIndex, num,refcount);        Imgcontrol (PageIndex, Count); }        Private voidBtnright_click (Objectsender, RoutedEventArgs e) {PageIndex+=1; Txtjumppage.text=pageindex.tostring (); Num=Convert.ToInt32 (Cbopagesize.text); Dgvlistbind (PageIndex, num,refcount);        Imgcontrol (PageIndex, Count); }        Private voidBtnlast_click (Objectsender, RoutedEventArgs e) {num=Convert.ToInt32 (Cbopagesize.text); PageIndex= count% num = =0? Count/num:count/num +1; Dgvlistbind (PageIndex, num,refcount); //There may be new data, so updatePageIndex = count% num = =0? Count/num:count/num +1; Txtjumppage.text=pageindex.tostring (); Dgvlistbind (PageIndex, num,refcount);        Imgcontrol (PageIndex, Count); }        Private voidBtnjump_click (Objectsender, RoutedEventArgs e) {            intindex =0; Try{Index=Convert.ToInt32 (Txtjumppage.text); }            Catch(Exception ex) {MessageBox.Show ("Please enter a number!"); return; } num=Convert.ToInt32 (Cbopagesize.text); intEnd = count% num = =0? Count/num:count/num +1; if(Index >end) {Index=end; Txtjumppage.text=end.            ToString (); } PageIndex=index; Dgvlistbind (PageIndex, num,refcount); Txtjumppage.text=pageindex.tostring (); Dgvlistbind (PageIndex, num,refcount);        Imgcontrol (PageIndex, Count); }        /// <summary>        ///Refresh/// </summary>        /// <param name= "Sender" ></param>        /// <param name= "E" ></param>         Public voidBtnrefresh_click (Objectsender, RoutedEventArgs e) {dgvlistbind (PageIndex, num,refcount); }

The call is simple,

In the place where this control is called, the implementation of the delegate onpagegetlist is good. Demo code Download

Devexpress for WPF grid paging

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.