Built-in page flip control five steps system. Windows. Forms. bindingnavigator

Source: Internet
Author: User

You can find this control in the toolbar on the left.

System. Windows. Forms. bindingnavigator

 

I would not have written such a blog post, but a new colleague said that technology should always be summarized. But I will write it down. For future use, you can refer.

 

1. Usage:

First, define several attributes.

Private int pagecurrent
{
Get
{
Return convert. toint32 (navcurrentpage. Text );
}
Set {navcurrentpage. Text = value. tostring ();}
}
Private int pagecount
{
Get {return convert. toint32 (navsumpage. Text );}
Set
{
Navsumpage. Text = value. tostring ();
}
}
Private int pagesize
{
Get {return 50 ;}
}

 

 

2. Query Method

 

Private void simplebutton#click (Object sender, eventargs E)
{
Int _ recordcount = 0;

List modellist = new dataio (). getbookartlist (pagecurrent = 0? 1: pagecurrent, pagesize, out _ recordcount);
pagecount = _ recordcount/pagesize;
setrolenavigatorstate ();
listboxcontrol1.items. clear ();


Listboxcontrol1.datasource = modellist;
Listboxcontrol1.displaymember = "title ";
Listboxcontrol1.valuemember = "url ";
}

 

3. Set button availability

 

Private void setrolenavigatorstate ()
{
If (pagecount> 0)
{
If (pagecurrent = 1)
{
This. navfirstpage. Enabled = false;
This. navprepage. Enabled = false;
This. navnextpage. Enabled = true;
This. navlastpage. Enabled = true;
}
Else if (pagecurrent = pagecount)
{
This. navfirstpage. Enabled = true;
This. navprepage. Enabled = true;
This. navnextpage. Enabled = false;
This. navlastpage. Enabled = false;
}
Else
{
This. navfirstpage. Enabled = true;
This. navprepage. Enabled = true;
This. navnextpage. Enabled = true;
This. navlastpage. Enabled = true;
}
}
Else if (pagecount <= 1)
{

This. navfirstpage. Enabled = false;
This. navprepage. Enabled = false;
This. navnextpage. Enabled = false;
This. navlastpage. Enabled = false;
}
}

4. Give the control a click event.

Void navigatorbox_itemclicked (Object sender, toolstripitemclickedeventargs E)
{
String itemname = E. clickeditem. Name;
Switch (itemname)
{

Case "navfirstpage ":
Pagecurrent = 1;

Simplebutton#click (null, null );

Break;
Case "navprepage ":
Pagecurrent --;
Simplebutton#click (null, null );

Break;
Case "navnextpage ":
Pagecurrent ++;
Simplebutton#click (null, null );

Break;
Case "navlastpage ":
Pagecurrent = pagecount;
Simplebutton#click (null, null );
Break;

}
}

 

 

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.