zoukankan      html  css  js  c++  java
  • 自带的翻页控件五个步骤 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;

                }
            }

  • 相关阅读:
    串口通信中接收数据时延迟处理与缓存处理的解决方案(C#)
    串口通讯接收数据的处理
    在C#程序设计中使用Win32类库
    C# Mutex对象学习经验
    我眼中的C# 3.0 Written by Allen Lee
    利用C#鼠标拖动TreeView节点
    richtextbox内文字自动滚动的例子
    在十六进制字符串与数值类型之间转换 C# 编程指南
    如何:指定符号位置和加载行为
    杂记20110321
  • 原文地址:https://www.cnblogs.com/qq4004229/p/2659873.html
Copyright © 2011-2022 走看看