1.图列展示

2.分页控件代码

Paging.Designer.cs

 partial class Paging
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region 组件设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Paging));
this.bindingNavigator = new System.Windows.Forms.BindingNavigator(this.components);
this.btnFirst = new System.Windows.Forms.ToolStripButton();
this.btnPrev = new System.Windows.Forms.ToolStripButton();
this.btnNext = new System.Windows.Forms.ToolStripButton();
this.btnLast = new System.Windows.Forms.ToolStripButton();
this.toolStripLabel6 = new System.Windows.Forms.ToolStripLabel();
this.toolStripLabel4 = new System.Windows.Forms.ToolStripLabel();
this.txtCurrentPage = new System.Windows.Forms.ToolStripTextBox();
this.toolStripLabel1 = new System.Windows.Forms.ToolStripLabel();
this.btnGo = new System.Windows.Forms.ToolStripButton();
this.toolStripLabel5 = new System.Windows.Forms.ToolStripLabel();
this.toolStripLabel2 = new System.Windows.Forms.ToolStripLabel();
this.lblPageCount = new System.Windows.Forms.ToolStripLabel();
this.toolStripLabel3 = new System.Windows.Forms.ToolStripLabel();
this.lblMaxPage = new System.Windows.Forms.ToolStripLabel();
((System.ComponentModel.ISupportInitialize)(this.bindingNavigator)).BeginInit();
this.bindingNavigator.SuspendLayout();
this.SuspendLayout();
//
// bindingNavigator
//
this.bindingNavigator.AddNewItem = null;
this.bindingNavigator.CountItem = null;
this.bindingNavigator.DeleteItem = null;
this.bindingNavigator.Dock = System.Windows.Forms.DockStyle.Bottom;
this.bindingNavigator.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.btnFirst,
this.btnPrev,
this.btnNext,
this.btnLast,
this.toolStripLabel6,
this.toolStripLabel4,
this.txtCurrentPage,
this.toolStripLabel1,
this.btnGo,
this.toolStripLabel5,
this.toolStripLabel2,
this.lblPageCount,
this.toolStripLabel3,
this.lblMaxPage});
this.bindingNavigator.Location = new System.Drawing.Point(, );
this.bindingNavigator.MoveFirstItem = null;
this.bindingNavigator.MoveLastItem = null;
this.bindingNavigator.MoveNextItem = null;
this.bindingNavigator.MovePreviousItem = null;
this.bindingNavigator.Name = "bindingNavigator";
this.bindingNavigator.PositionItem = null;
this.bindingNavigator.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
this.bindingNavigator.Size = new System.Drawing.Size(, );
this.bindingNavigator.TabIndex = ;
this.bindingNavigator.Text = "bindingNavigator1";
//
// btnFirst
//
this.btnFirst.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.btnFirst.Image = ((System.Drawing.Image)(resources.GetObject("btnFirst.Image")));
this.btnFirst.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btnFirst.Name = "btnFirst";
this.btnFirst.Size = new System.Drawing.Size(, );
this.btnFirst.Text = "首页";
this.btnFirst.Click += new System.EventHandler(this.btnFirst_Click);
//
// btnPrev
//
this.btnPrev.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.btnPrev.Image = ((System.Drawing.Image)(resources.GetObject("btnPrev.Image")));
this.btnPrev.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btnPrev.Name = "btnPrev";
this.btnPrev.Size = new System.Drawing.Size(, );
this.btnPrev.Text = "上页";
this.btnPrev.Click += new System.EventHandler(this.btnPrev_Click);
//
// btnNext
//
this.btnNext.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.btnNext.Image = ((System.Drawing.Image)(resources.GetObject("btnNext.Image")));
this.btnNext.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btnNext.Name = "btnNext";
this.btnNext.Size = new System.Drawing.Size(, );
this.btnNext.Text = "下页";
this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
//
// btnLast
//
this.btnLast.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.btnLast.Image = ((System.Drawing.Image)(resources.GetObject("btnLast.Image")));
this.btnLast.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btnLast.Name = "btnLast";
this.btnLast.Size = new System.Drawing.Size(, );
this.btnLast.Text = "未页";
this.btnLast.Click += new System.EventHandler(this.btnLast_Click);
//
// toolStripLabel6
//
this.toolStripLabel6.Name = "toolStripLabel6";
this.toolStripLabel6.Size = new System.Drawing.Size(, );
this.toolStripLabel6.Text = " ";
//
// toolStripLabel4
//
this.toolStripLabel4.Name = "toolStripLabel4";
this.toolStripLabel4.Size = new System.Drawing.Size(, );
this.toolStripLabel4.Text = "第";
//
// txtCurrentPage
//
this.txtCurrentPage.Name = "txtCurrentPage";
this.txtCurrentPage.Size = new System.Drawing.Size(, );
//
// toolStripLabel1
//
this.toolStripLabel1.Name = "toolStripLabel1";
this.toolStripLabel1.Size = new System.Drawing.Size(, );
this.toolStripLabel1.Text = "页";
//
// btnGo
//
this.btnGo.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.btnGo.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold);
this.btnGo.Image = ((System.Drawing.Image)(resources.GetObject("btnGo.Image")));
this.btnGo.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btnGo.Name = "btnGo";
this.btnGo.Size = new System.Drawing.Size(, );
this.btnGo.Text = "GO";
this.btnGo.Click += new System.EventHandler(this.btnGo_Click);
//
// toolStripLabel5
//
this.toolStripLabel5.Name = "toolStripLabel5";
this.toolStripLabel5.Size = new System.Drawing.Size(, );
this.toolStripLabel5.Text = " ";
//
// toolStripLabel2
//
this.toolStripLabel2.Name = "toolStripLabel2";
this.toolStripLabel2.Size = new System.Drawing.Size(, );
this.toolStripLabel2.Text = "共";
//
// lblPageCount
//
this.lblPageCount.Name = "lblPageCount";
this.lblPageCount.Size = new System.Drawing.Size(, );
this.lblPageCount.Text = "lblPageCount";
//
// toolStripLabel3
//
this.toolStripLabel3.Name = "toolStripLabel3";
this.toolStripLabel3.Size = new System.Drawing.Size(, );
this.toolStripLabel3.Text = "页";
//
// lblMaxPage
//
this.lblMaxPage.Name = "lblMaxPage";
this.lblMaxPage.Size = new System.Drawing.Size(, );
this.lblMaxPage.Text = "lblMaxPage";
//
// Paging
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.bindingNavigator);
this.Name = "Paging";
this.Size = new System.Drawing.Size(, );
((System.ComponentModel.ISupportInitialize)(this.bindingNavigator)).EndInit();
this.bindingNavigator.ResumeLayout(false);
this.bindingNavigator.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout(); } #endregion public System.Windows.Forms.BindingNavigator bindingNavigator;
private System.Windows.Forms.ToolStripButton btnFirst;
private System.Windows.Forms.ToolStripButton btnPrev;
private System.Windows.Forms.ToolStripButton btnNext;
private System.Windows.Forms.ToolStripButton btnLast;
private System.Windows.Forms.ToolStripLabel toolStripLabel6;
private System.Windows.Forms.ToolStripLabel toolStripLabel4;
private System.Windows.Forms.ToolStripTextBox txtCurrentPage;
private System.Windows.Forms.ToolStripLabel toolStripLabel1;
private System.Windows.Forms.ToolStripButton btnGo;
private System.Windows.Forms.ToolStripLabel toolStripLabel5;
private System.Windows.Forms.ToolStripLabel toolStripLabel2;
private System.Windows.Forms.ToolStripLabel lblPageCount;
private System.Windows.Forms.ToolStripLabel toolStripLabel3;
private System.Windows.Forms.ToolStripLabel lblMaxPage;
}

Paging.cs

  /// <summary>
/// 申明委托
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
public delegate int EventPagingHandler(EventPagingArg e);
public partial class Paging : UserControl
{
public Paging()
{
InitializeComponent();
}
public event EventPagingHandler EventPaging;
/// <summary>
/// 每页显示记录数
/// </summary>
private int _pageSize = ;
/// <summary>
/// 每页显示记录数
/// </summary>
public int PageSize
{
get { return _pageSize; }
set
{
_pageSize = value;
GetPageCount();
}
} private int _nMax = ;
/// <summary>
/// 总记录数
/// </summary>
public int NMax
{
get { return _nMax; }
set
{
_nMax = value;
GetPageCount();
}
} private int _pageCount = ;
/// <summary>
/// 页数=总记录数/每页显示记录数
/// </summary>
public int PageCount
{
get { return _pageCount; }
set { _pageCount = value; }
} private int _pageCurrent = ;
/// <summary>
/// 当前页号
/// </summary>
public int PageCurrent
{
get { return _pageCurrent; }
set { _pageCurrent = value; }
}
private DataTable _dataSource;
/// <summary>
/// 数据源
/// </summary>
public DataTable DataSource
{
get { return _dataSource; }
set
{
_dataSource = value;
}
}
public BindingNavigator ToolBar
{
get { return this.bindingNavigator; }
}
private void GetPageCount()
{
if (this.NMax > )
{
this.PageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(this.NMax) / Convert.ToDouble(this.PageSize)));
}
else
{
this.PageCount = ;
}
}
/// <summary>
/// 翻页控件数据绑定的方法
/// </summary>
public void Bind()
{
if (this.EventPaging != null)
{
this.NMax = this.EventPaging(new EventPagingArg(this.PageCurrent));
} if (this.PageCurrent > this.PageCount)
{
this.PageCurrent = this.PageCount;
}
if (this.PageCount == )
{
this.PageCurrent = ;
}
lblPageCount.Text = this.PageCount.ToString();
this.lblMaxPage.Text = "共" + this.NMax.ToString() + "条记录";
this.txtCurrentPage.Text = this.PageCurrent.ToString(); if (this.PageCurrent == )
{
this.btnPrev.Enabled = false;
this.btnFirst.Enabled = false;
}
else
{
btnPrev.Enabled = true;
btnFirst.Enabled = true;
} if (this.PageCurrent == this.PageCount)
{
this.btnLast.Enabled = false;
this.btnNext.Enabled = false;
}
else
{
btnLast.Enabled = true;
btnNext.Enabled = true;
} if (this.NMax == )
{
btnNext.Enabled = false;
btnLast.Enabled = false;
btnFirst.Enabled = false;
btnPrev.Enabled = false;
}
} private void btnFirst_Click(object sender, EventArgs e)
{
PageCurrent = ;
this.Bind();
} private void btnPrev_Click(object sender, EventArgs e)
{
PageCurrent -= ;
if (PageCurrent <= )
{
PageCurrent = ;
}
this.Bind();
} private void btnNext_Click(object sender, EventArgs e)
{
this.PageCurrent += ;
if (PageCurrent > PageCount)
{
PageCurrent = PageCount;
}
this.Bind();
} private void btnLast_Click(object sender, EventArgs e)
{
PageCurrent = PageCount;
this.Bind();
} private void btnGo_Click(object sender, EventArgs e)
{
if (this.txtCurrentPage.Text != null && txtCurrentPage.Text != "")
{
if (Int32.TryParse(txtCurrentPage.Text, out _pageCurrent))
{
this.Bind();
}
else
{
MessageBox.Show("输入数字格式错误!");
}
}
} private void txtCurrentPage_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.Bind();
}
} }
/// <summary>
/// 自定义事件数据基类
/// </summary>
public class EventPagingArg : EventArgs
{
private int _intPageIndex;
public EventPagingArg(int PageIndex)
{
_intPageIndex = PageIndex;
}
}

使用:
PagingHelper

 class PagingHelper
{ private int _PageSize = ;
private int _PageIndex = ;
private int _TotalCount = ;
private string _TableName;//表名
private string _QueryFieldName = "*";//表字段FieldStr
private string _OrderStr = string.Empty; //排序_SortStr
private string _QueryCondition = string.Empty;//查询的条件 RowFilter
private string _PrimaryKey = string.Empty;//主键 /// <summary>
/// 显示页数
/// </summary>
public int PageSize
{
get
{
return _PageSize; }
set
{
_PageSize = value;
}
}
/// <summary>
/// 当前页
/// </summary>
public int PageIndex
{
get
{
return _PageIndex;
}
set
{
_PageIndex = value;
}
} /// <summary>
/// 总记录数
/// </summary>
public int TotalCount
{
get
{
return _TotalCount;
}
}
/// <summary>
/// 表名,包括视图
/// </summary>
public string TableName
{
get
{
return _TableName;
}
set
{
_TableName = value;
}
}
/// <summary>
/// 表字段FieldStr
/// </summary>
public string QueryFieldName
{
get
{
return _QueryFieldName;
}
set
{
_QueryFieldName = value;
}
}
/// <summary>
/// 排序字段
/// </summary>
public string OrderStr
{
get
{
return _OrderStr;
}
set
{
_OrderStr = value;
}
}
public DataTable QueryDataTable()
{
//这里调用存储过程实现数据读取
//展示就用本地测试数据
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Name", typeof(string));
_TotalCount = ; int index = PageIndex == ? : PageIndex * PageSize;
for (int i = index; i < index+PageSize; i++)
{
dt.Rows.Add(i, "Name" + i.ToString());
}
dt.AcceptChanges(); return dt;
}
}

测试页面调用:

 private void Form1_Load(object sender, EventArgs e)
{
this.paging1.PageCurrent = ;
this.paging1.Bind();
} private int paging1_EventPaging(EventPagingArg e)
{
return Bind(this.paging1.PageCurrent);
}
private int Bind(int pagecurrent)
{
PagingHelper phelper = new PagingHelper();
phelper.PageIndex = pagecurrent;
paging1.PageSize = ;
DataTable dt = phelper.QueryDataTable();
this.dataGridView1.DataSource = dt.DefaultView;
return phelper.TotalCount;
}

Winform 分页的更多相关文章

  1. 在DevExpress程序中使用Winform分页控件直接录入数据并保存

    一般情况下,我们都倾向于使用一个组织比较好的独立界面来录入或者展示相关的数据,这样处理比较规范,也方便显示比较复杂的数据.不过在一些情况下,我们也可能需要直接在GridView表格上直接录入或者修改数 ...

  2. winform 分页控件

    http://www.cnblogs.com/liuyunsheng/p/4853387.html http://www.cnblogs.com/wuhuacong/archive/2011/07/0 ...

  3. 开发框架模块视频系列(2)-Winform分页控件介绍

    在软件开发过程中,为了节省开发时间,提高开发效率,统一用户处理界面,尽可能使用成熟.功能强大的分页控件,这款Winform环境下的分页控件,集成了数据分页.内容提示.数据打印.数据导出.表头中文转义等 ...

  4. 类似web风格的 Winform 分页控件

    背景 最近做一个Winform的小程序,需要用到分页,由于之前一直在用 TonyPagerForWinForm.dll ,但该库没有源代码,网上找的也不全面,索性就准备自己改造一个.在园子里翻了一下, ...

  5. Winform分页控件

    设计界面: 控件代码: using System; using System.Collections.Generic; using System.ComponentModel; using Syste ...

  6. [原创]WinForm分页控件制作

    先简单说一下思路: 1.做一个分页控件的导航类,即记录总页数.当前页.每页记录数,下一页.上一页.跳转等操作的页数变更. class PageNavigation{/// <summary> ...

  7. winform分页管理

    注意:其中可能用到部分自定义的扩展方法,在使用中需自己修改一下 /// <summary> /// 分页管理 /// </summary> public class Pagin ...

  8. winform 分页 分类: WinForm 2014-05-16 15:30 257人阅读 评论(0) 收藏

    说明:(1)如果对分页的感兴趣的话,可以看一下我传的存储过程("SQL 存储过程 分页")               (2)分页,第一页.上一页,下一页.最后一页只调用点击(cl ...

  9. 【NET】Winform分页控件初探

    public partial class WinFormPager : UserControl { ; /// <summary> /// 当前页 /// </summary> ...

  10. DEV Winform分页用户组件

    资源部分在QQ群:616945527基于服务端数据分页,你也可以修改成本地分页.调用方法添加用户控件到窗体 public int curPage = 1;public int pageSize = 1 ...

随机推荐

  1. HTML中被废弃的标签<b><u><i><s>

    <strong>代替<b>给文字加粗 <ins>代替<u>给文本添加下划线 <em>代替<i>将文本倾斜 <del> ...

  2. Hadoop2.7.1配置NameNode+ResourceManager高可用原理分析

    关于NameNode高可靠需要配置的文件有core-site.xml和hdfs-site.xml 关于ResourceManager高可靠需要配置的文件有yarn-site.xml 逻辑结构: Nam ...

  3. [NOIP2019模拟赛][AT2381] Nuske vs Phantom Thnook

    题目链接 评测姬好快啊(港记号?)暴力40pts变成60pts 因为题目说了保证蓝色点两两之间只有一条路径,所以肯定组成了一棵树,而对于每次询问的x1,y1,x2,y2的子矩阵中就存在着一个森林 不难 ...

  4. CentOS6.3搭建ZooKeeper伪集群

    1. 将zookeeper安装包移动至/home, 解压后改名为zookeeper 相关命令 # 解压 .tar.gz # 重命名 zookeeper 2. 进入zookeeper/conf/目录下, ...

  5. Vim操作 -- 多段复位粘贴

    Vim可以多段复制.粘贴.即,内容X复制到寄存器“1”,内容Y复制到寄存器“2”:粘贴时可以选择从“1”还是“2”粘贴. (1) Vim有13个粘贴板,分别是0.1.2.....9.a.“.+:用:r ...

  6. PAT甲级——A1099 Build A Binary Search Tree

    A Binary Search Tree (BST) is recursively defined as a binary tree which has the following propertie ...

  7. quartz 定时任务配置文件信息

    quartz 定时任务配置文件有五大要素,配置好这五大要素,quartz 就能够正常的工作. 五大要素分别是: 1.工作的 bean:具体是哪个 Java 类来作为定时任务的文件入口,并配置该 bea ...

  8. SQLServer 2008 的数据库日志清理

    -- SQLServer 2008 的数据库日志清理 ,与 Sql2000 或 2005 的方法不一样,需要采用 下面的sql来清理 USE [master] GO ALTER DATABASE [数 ...

  9. 微信小程序之组件的集合(六)

    这个将是最后一篇关于小程序的记录了,课程接近尾声,最后一个是关于用户的page页面,看看这个页面中有哪些值得学习的地方! 一.page中my开发 这个主要是展示用户喜欢的杂志,以及用户的信息,需要创建 ...

  10. Mysql8+mybatisGenerator (mysql 8的逆向工程)

    最近试了一下mysql8的逆向工程工具 1.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOC ...