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;
}
}