自带的翻页控件五个步骤 System.Windows.Forms.BindingNavigator

在左边的工具栏中可以找到这个控件

System.Windows.Forms.BindingNavigator

 

我本来不会写这种博文的,但一个新同事说技术这事东东要常总结。不过我写下来。也是为了以后用的时候可以参考一下。

 

1.使用方法:

首先定义几个属性

 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.查询方法

 

   private void simpleButton1_Click(object sender, EventArgs e)
        {
            int _recordCount = 0;

            List<BookInfo> 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.设置按钮可用性

 

   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.给控件一个点击事件

 void Navigatorbox_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            string itemName = e.ClickedItem.Name;
            switch (itemName)
            {

                case "navFirstPage":
                    PageCurrent = 1;
                  
                    simpleButton1_Click(null, null);
             
                    break;
                case "navPrePage":
                    PageCurrent--;
                    simpleButton1_Click(null, null);
                
                    break;
                case "navNextPage":
                    PageCurrent++;
                    simpleButton1_Click(null, null);
                 
                    break;
                case "navLastPage":
                    PageCurrent = PageCount;
                    simpleButton1_Click(null, null);
                    break;

            }
        }

 

 

posted @ 2012-08-28 10:47  咸鱼公子  Views(4600)  Comments(0Edit  收藏  举报