zoukankan      html  css  js  c++  java
  • Winform DataGridView 自定义分页

    需要一个、BindingNavigate、BindingSource控件,分别命名为PageOperation,dataSource;

    首先,定义私有字段:

            private int pageTotal;

            private int pageSize = 10;

            private int pageIndex = 1;

    然后是赋值 dataSource.DataSource = list;


    #region 分页相关

            //分页操作

            private void PageOperation(ToolStripItemClickedEventArgs e)

            {

                if (e.ClickedItem.Text == "首页")

                {

                    FirstPageOperation();

                }

                if (e.ClickedItem.Text == "上一页")

                {

                    PrevPageOperation();

                }

                if (e.ClickedItem.Text == "下一页")

                {

                    NextPageOperation();

                }

                if (e.ClickedItem.Text == "尾页")

                {

                    LastPageOperation();

                }

            }

            //尾页

            private void LastPageOperation()

            {

                pageIndex = pageTotal;

                if (pageIndex + 1 >= pageTotal)

                {

                    PageWithLastOfNext(false);

                }

                if (pageTotal > 1)

                {

                    PageWithPrevOfFirst(true);

                }

            }

            //下一页

            private void NextPageOperation()

            {

                if (pageIndex + 1 >= pageTotal)

                {

                    PageWithLastOfNext(false);

                }

                pageIndex++;

                if (pageTotal > 1)

                {

                    PageWithPrevOfFirst(true);

                }

            }

            //上一页

            private void PrevPageOperation()

            {

                if (pageIndex - 1 <= 1)

                {

                    PageWithPrevOfFirst(false);

                }

                pageIndex--;

                if (pageTotal > 1)

                {

                    PageWithLastOfNext(true);

                }

            }

            //首页

            private void FirstPageOperation()

            {

                pageIndex = 1;

                if (pageIndex - 1 <= 1)

                {

                    PageWithPrevOfFirst(false);

                }

                if (pageTotal > 1)

                {

                    PageWithLastOfNext(true);

                }

            }


            private void PageWithPrevOfFirst(bool enabled)

            {

                        itemPagePrev.Enabled = enabled;

                        iitemPageFirst.Enabled = enabled;

            }


            private void PageWithLastOfNext(bool enabled)

            {

                        itemPageLast.Enabled = enabled;

                        itemPageNext.Enabled = enabled;

            }


            #endregion



  • 相关阅读:
    css样式优先级
    combobox addobject 字符串
    转:delphi dpk编译 Error: E2161 RLINK32: Unsupported 16bit resource in file xxx 问题解决
    ansistring-->unionstring 怪码
    一定要牢记软件工程的铁律
    转:oracle 删除表空间错误 提示:ora-02429:无法删除用于强制唯一
    delphi7 string 转到 PWideChar 用于连接unicode dll调用
    delphi中调用 DLL一定要注意声明函数的大小写
    slinebreak、 raise用法
    idHttp 中GET POST应用
  • 原文地址:https://www.cnblogs.com/rsls/p/4364120.html
Copyright © 2011-2022 走看看