网址大全 | 文章大全 | 精选文摘 | 桌面壁纸 | 站长资源 | 在线手册 | 幽默笑话 | 天气预报 | FLASH    | 歇后语
便民查询 | 成语词典 | 五笔字典 | 新华字典 | 周公解梦 | 在线算命 | 生日密码 | 网络电台 | 网站留言 | 许愿墙
您的位置:首页 >> 文章大全 > 网络编程 > C#
站内搜索:
网络编程专栏
VB.NETASP
ASP.NETC#
数据库PHP
技巧篇Delphi
相关文章
没有相关文章
百度搜索 全网 本站
本类排行 more>>
·C#的IO使用
·c#中如何获取时间!
·C#实现的18位身份证格...
·用C#读取XML的元素和...
·winfrom中的datagrid...
·如何用C#语言构造蜘蛛...
·C#的消息处理方法
·C#部分函数列表
·C#资料下载收藏
·实现C#和VB.net之间的...
最新文章 more>>
·《网站配色方案》系列...
·《网站配色方案》系列...
·岳飞传的流程攻略
·百度漂亮 但Google更...
·个人站长的胜利 新网...
·搜搜问问抢不了百度知...
·视频网站接连败退 营...
·曹操传 杨家将传奇 官...
·专家为股民支招:网络...
·优秀站长访谈:个人网...
winfrom中的datagrid的翻页类

[ 作者:佚名 来源:网络 点击数:104 加入时间:2006-1-14 ]

【双击左键自动滚屏】【图片上滚动鼠标滚轮变焦图片】 【字体:放大 正常 缩小】 字体颜色:
便民查询  中华五千年  世界五千年  万年历  天气预报  周公解梦  脑筋急转弯  在线翻译  电信话费查询
using System;
using System.Windows.Forms;
using System.Data;
namespace HRMS.Common
{
/// <summary>
/// HRDataGrid 的摘要说明。
/// </summary>
public class HRDataGrid:DataGrid
{
  private void InitializeComponent()
  {
   ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
   ((System.ComponentModel.ISupportInitialize)(this)).EndInit();

  }

  public HRDataGrid()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }
  /// <summary>
  /// 总页数
  /// </summary>
  private int pageCount=1;
  /// <summary>
  /// 每页行数
  /// </summary>
  private int pageRows=40;
  /// <summary>
  /// 总行数
  /// </summary>
  private int rowCount=1;
  /// <summary>
  /// 当前页
  /// </summary>
  private int curentPageIndex=0;
  /// <summary>
  /// 能否前进
  /// </summary>
  private bool canPri=false;
  /// <summary>
  /// 能否后退
  /// </summary>
  private bool canNext=false;

  /// <summary>
  /// 邦订表
  /// </summary>
  private DataTable buildDataTable=new DataTable();

  /// <summary>
  /// 邦订对应的表
  /// </summary>
  /// <param name="dt"></param>
  public void SetHRDataSource(DataTable dt)
  {
   this.buildDataTable=dt;
   this.rowCount=dt.Rows.Count;
   this.pageCount=rowCount/pageRows;
   if(rowCount % pageRows>0)
   {
    this.pageCount=this.pageCount+1;
   }
   if(pageCount<1)
   {
    PageCount=1;
   }
   if(pageCount>curentPageIndex)
   {
    this.canNext=true;
   }
   else
   {
    this.canNext=false;
   }
   if(curentPageIndex>1)
   {
    this.canPri=true;
   }
   else
   {
    this.canPri=false;
   }
   
   BuildTable(this.curentPageIndex);
  }


  /// <summary>
  /// 下一页
  /// </summary>
  public void NextPage()
  {
   if(!canNext)
   {
    MessageBox.Show("已经到最后一页!");
    return;
   }
   this.canPri=true;
   this.curentPageIndex=curentPageIndex+1;
   if(curentPageIndex>=this.pageCount)
   {
    this.canNext=false;
   }
   else
   {
    this.canNext=true;
   }
   BuildTable(curentPageIndex);
  }

  /// <summary>
  /// 前一页
  /// </summary>
  public void PriPage()
  {
   if(!canPri)
   {
    MessageBox.Show("已经到最前一页!");
    return;
   }
   this.canNext=true;
   this.curentPageIndex=curentPageIndex-1;
   if(curentPageIndex<=1)
   {
    this.canPri=false;
   }
   else
   {
    this.canPri=true;
   }
   BuildTable(curentPageIndex);
  }

  private void BuildTable(int index)
  {
   if(index<1)
   {
    index=1;
   }
   if(index>this.pageCount)
   {
    index=this.pageCount;
    //throw new Exception("需要邦订的页数超出范围!");
   }
   DataTable tempTable=this.buildDataTable.Copy();
   tempTable.Clear();
   int start=(index-1)*pageRows;
   int end=index*pageRows;
   if(end>this.rowCount)
   {
    end=this.rowCount;
   }
   for(int intx=start;intx<end;intx++)
   {
    DataRow dr=tempTable.NewRow();
    dr.ItemArray=((DataRow)(this.buildDataTable.Rows[intx])).ItemArray;
    tempTable.Rows.Add(dr);
   }
   this.DataSource=tempTable;
  }

  public bool CanPri
  {
   set
   {
    this.canPri=value;
   }
   get
   {
    return this.canPri;
   }
  }
  public bool CanNext
  {
   set
   {
    this.canNext=value;
   }
   get
   {
    return this.canNext;
   }
  }

  public int CurentPageIndex
  {
   set
   {
    this.curentPageIndex=value;
   }
   get
   {
    return this.curentPageIndex;
   }
  }

  public int RowCount
  {
   set
   {
    this.rowCount=value;
   }
   get
   {
    return this.rowCount;
   }
  }

  public int PageCount
  {
   set
   {
    this.pageCount=value;
   }
   get
   {
    return this.pageCount;
   }
  }


  public int PageRows
  {
   set
   {
    this.pageRows=value;
   }
   get
   {
    return this.pageRows;
   }
  }

  public DataTable BuildDataTable
  {
   set
   {
    this.buildDataTable=value;
   }
   get
   {
    return this.buildDataTable;
   }
  }
}
}




调用这个类:
//Set dataTable
public void BuildingGridData(DataSet ds)
  {
      this.dataGrid_person.SetHRDataSource(ds.Tables[0]);
   this.toolBarButton_priPage.Enabled=dataGrid_person.CanPri;
   this.toolBarButton_nextPage.Enabled=dataGrid_person.CanNext;
   this.statusBarPanel_GrifInfo.Text="第"+dataGrid_person.CurentPageIndex.ToString()+"页/共"+dataGrid_person.PageCount.ToString()+"页";
   this.statusBarPanel_GridRows.Text="共"+dataGrid_person.RowCount.ToString()+"笔记录";
  }

//点按上一页
this.dataGrid_person.PriPage();
     this.toolBarButton_priPage.Enabled=dataGrid_person.CanPri;
     this.toolBarButton_nextPage.Enabled=dataGrid_person.CanNext;

//点按下一页
this.dataGrid_person.NextPage();
     this.toolBarButton_priPage.Enabled=dataGrid_person.CanPri;
     this.toolBarButton_nextPage.Enabled=dataGrid_person.CanNext;



国家纸币  自考信息  度量转换  搜索引擎指南  城市经纬度  脑筋急转弯  各国资料  名言辞典  违章查询
·上一篇文章:Window.Open详解
·下一篇文章:asp文件夹
百度搜索更多内容:winfrom中的datagrid的翻页类
推荐文档】 【打印文档】 【返回页首】 【关闭窗口