WinForm自定分页

-------------------自定DataGrid

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace Pagination.CommonTools
{
 public class PageGrid:DataGrid
 {
  private System.ComponentModel.Container components = null;

  public PageGrid()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }
  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if( components != null )
     components.Dispose();
   }
   base.Dispose( disposing );
  }

  #region 组件设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器
  /// 修改此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   components = new System.ComponentModel.Container();
  }
  #endregion

  protected override void OnPaint(PaintEventArgs pe)
  {
   // TODO: 在此添加自定义绘画代码

   // 调用基类 OnPaint
   base.OnPaint(pe);
  }
  private int pageCount=1;// 总页数
  private int pageRows=40;//每页行数
  private int rowCount=1;//总行数
  private int currentPageIndex=0;//当前页号
  private bool canPri=false; //能否前进
  private bool canNext=false; //能否后退
  private DataTable originalTable=new DataTable(); //原始表

  public void SetPageDataSource(DataTable dt) //对原始表进行处理,得到总行数rowCount,总页数pageCount
  {
   this.originalTable=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>currentPageIndex) //首次加载时对canNext, canPri处理
   {
    this.canNext=true;
   }
   else
   {
    this.canNext=false;
   }
   if(currentPageIndex>1)
   {
    this.canPri=true;
   }
   else
   {
    this.canPri=false;
   }

   BuildTable(this.currentPageIndex);
  }
  private void BuildTable(int index)//每页绑定到Temp表
  {
   if(index<1)
   {
    index=1;
   }
   if(index>this.pageCount)
   {
    index=this.pageCount;    
   }
   DataTable tempTable=this.originalTable.Copy();
   tempTable.Clear();
   int start=(index-1)*pageRows;
   int end=index*pageRows;
   if(end>this.rowCount)
   {
    end=this.rowCount;
   }
   for(int i=start;i<end;i++)
   {
    DataRow dr=tempTable.NewRow();
    dr.ItemArray=((DataRow)(this.originalTable.Rows[i])).ItemArray;
    tempTable.Rows.Add(dr);
   }
   this.DataSource=tempTable;
  }
  public void PriPage()
  {
   this.canNext=true;
   this.currentPageIndex=currentPageIndex-1;
   if(currentPageIndex<=1)
   {
    this.canPri=false;
   }
   else
   {
    this.canPri=true;
   }
   BuildTable(currentPageIndex);
  }

  public void NextPage()
  {
   this.canPri=true;
   this.currentPageIndex=currentPageIndex+1;
   if(currentPageIndex>=this.pageCount)
   {
    this.canNext=false;
   }
   else
   {
    this.canNext=true;
   }
   BuildTable(currentPageIndex);
  }
  
  public void FirstPage()
  {
   if(currentPageIndex ==1)
   {
    MessageBox.Show("已经到第一页!");
    return;
   }
   if(pageCount>1)
   {
    this.canPri=false;
    this.canNext=true;    
   }
   else
   {
    this.canPri=false;
    this.canNext=false;    
   }
   currentPageIndex =1;
   BuildTable(currentPageIndex);
  }
  public void LastPage()
  {
  if(currentPageIndex ==pageCount)
   {
    MessageBox.Show("已经到第一页!");
    return;
   }
  else if(PageCount>1)
  {
   this.canNext = false;
   this.canPri= true;   
  }
  else
  {
   this.canNext = false;
   this.canPri  = false;
  }
  this.currentPageIndex =pageCount;
  BuildTable(currentPageIndex);
}

  public void GoPage(int goindex)
  {
   if(goindex>pageCount)
   {
    MessageBox.Show("最大页数为"+ pageCount +",我们将会为您转到最后页", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
    currentPageIndex = pageCount;
    if(pageCount>1)
    {
     canPri= true;
     canNext = false;
    }
    else
    {
     canPri= false;
     canNext = false;
    }
   }
   else if(goindex==pageCount)
   {
    currentPageIndex = pageCount;
    if(pageCount>1)
    {
     canPri= true;
     canNext = false;
    }
    else
    {
     canPri= false;
     canNext = false;
    }    
   }
   else if(goindex<1)
   {
    MessageBox.Show("最小页数为1页,我们将会为您转到第一页", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
    currentPageIndex = 1;
    if(pageCount>1)
    {
     canPri= false;
     canNext = true;
    }
    else
    {
     canPri= false;
     canNext = false;
    }
   }
   else if(goindex==1)
   {
    if(pageCount>1)
    {
     canPri= false;
     canNext = true;
    }
    else
    {
     canPri= false;
     canNext = false;
    }
    currentPageIndex = 1;
   }
   else
   {
    currentPageIndex = goindex;
    if(pageCount>1)
    {
     canPri= true;
     canNext = true;
    }
    else
    {
     canPri= false;
     canNext = false;
    }
   }   
   BuildTable(currentPageIndex);
  }


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

  public int CurrentPageIndex
  {
   set
   {
    this.currentPageIndex=value;
   }
   get
   {
    return this.currentPageIndex;
   }
  }

  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;
   }
  }
 }

}

------------------------------------------------

演示用例

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Pagination.CommonTools;

namespace WinFormPageination
{
 /// <summary>
 /// Form1 的摘要说明。
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
  private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
  private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
  private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
  private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
  private System.Data.SqlClient.SqlConnection sqlConnection1;
  private System.Data.DataSet dataSet1;
  private PageGrid dataGrid1;
  private System.Data.DataColumn dataColumn1;
  private System.Windows.Forms.StatusBarPanel GridRows;
  private System.Windows.Forms.StatusBar statusBarPanel;
  private System.Windows.Forms.Button lastPage;
  private System.Windows.Forms.Button firstPage;
  private System.Windows.Forms.Button btnGoPage;
  private System.Windows.Forms.TextBox txtGoPage;
  private System.Windows.Forms.Label label2;
  private System.Windows.Forms.Label label3;
  private System.Windows.Forms.ComboBox cmbPage;
  private System.Windows.Forms.StatusBarPanel GridInfo;
  private System.Windows.Forms.Button nextPage;
  private System.Windows.Forms.Button previousPage;
  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private System.ComponentModel.Container components = null;

  public Form1()
  {
   //
   // Windows 窗体设计器支持所必需的
   //  
   
   InitializeComponent();
   sqlDataAdapter1.Fill(dataSet1,"customer");
   dataGrid1.SetPageDataSource(dataSet1.Tables["customer"]);   
   loadCombBoxItem();

   previousPage.Enabled=dataGrid1.CanPri;
   nextPage.Enabled=dataGrid1.CanNext;
   GridInfo.Text="第"+dataGrid1.CurrentPageIndex.ToString()+"页/共"+dataGrid1.PageCount.ToString()+"页";
   GridRows.Text="每页"+dataGrid1.PageRows.ToString() +"笔记录"+"/共"+dataGrid1.RowCount.ToString()+"笔记录";

   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
   this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
   this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
   this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
   this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
   this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
   this.dataSet1 = new System.Data.DataSet();
   this.dataGrid1 = new Pagination.CommonTools.PageGrid();
   this.dataColumn1 = new System.Data.DataColumn();
   this.previousPage = new System.Windows.Forms.Button();
   this.nextPage = new System.Windows.Forms.Button();
   this.statusBarPanel = new System.Windows.Forms.StatusBar();
   this.GridInfo = new System.Windows.Forms.StatusBarPanel();
   this.GridRows = new System.Windows.Forms.StatusBarPanel();
   this.lastPage = new System.Windows.Forms.Button();
   this.firstPage = new System.Windows.Forms.Button();
   this.btnGoPage = new System.Windows.Forms.Button();
   this.txtGoPage = new System.Windows.Forms.TextBox();
   this.label2 = new System.Windows.Forms.Label();
   this.label3 = new System.Windows.Forms.Label();
   this.cmbPage = new System.Windows.Forms.ComboBox();
   ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
   ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
   ((System.ComponentModel.ISupportInitialize)(this.GridInfo)).BeginInit();
   ((System.ComponentModel.ISupportInitialize)(this.GridRows)).BeginInit();
   this.SuspendLayout();
   //
   // sqlDataAdapter1
   //
   this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
   this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
   this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
   this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
                           new System.Data.Common.DataTableMapping("Table", "Customers", new System.Data.Common.DataColumnMapping[] {
                                                       new System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"),
                                                       new System.Data.Common.DataColumnMapping("CompanyName", "CompanyName"),
                                                       new System.Data.Common.DataColumnMapping("ContactName", "ContactName"),
                                                       new System.Data.Common.DataColumnMapping("ContactTitle", "ContactTitle"),
                                                       new System.Data.Common.DataColumnMapping("Address", "Address"),
                                                       new System.Data.Common.DataColumnMapping("City", "City"),
                                                       new System.Data.Common.DataColumnMapping("Region", "Region"),
                                                       new System.Data.Common.DataColumnMapping("PostalCode", "PostalCode"),
                                                       new System.Data.Common.DataColumnMapping("Country", "Country"),
                                                       new System.Data.Common.DataColumnMapping("Phone", "Phone"),
                                                       new System.Data.Common.DataColumnMapping("Fax", "Fax")})});
   this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
   //
   // sqlDeleteCommand1
   //
   this.sqlDeleteCommand1.CommandText = @"DELETE FROM Customers WHERE (CustomerID = @Original_CustomerID) AND (Address = @Original_Address OR @Original_Address IS NULL AND Address IS NULL) AND (City = @Original_City OR @Original_City IS NULL AND City IS NULL) AND (CompanyName = @Original_CompanyName) AND (ContactName = @Original_ContactName OR @Original_ContactName IS NULL AND ContactName IS NULL) AND (ContactTitle = @Original_ContactTitle OR @Original_ContactTitle IS NULL AND ContactTitle IS NULL) AND (Country = @Original_Country OR @Original_Country IS NULL AND Country IS NULL) AND (Fax = @Original_Fax OR @Original_Fax IS NULL AND Fax IS NULL) AND (Phone = @Original_Phone OR @Original_Phone IS NULL AND Phone IS NULL) AND (PostalCode = @Original_PostalCode OR @Original_PostalCode IS NULL AND PostalCode IS NULL) AND (Region = @Original_Region OR @Original_Region IS NULL AND Region IS NULL)";
   this.sqlDeleteCommand1.Connection = this.sqlConnection1;
   this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CustomerID", System.Data.SqlDbType.NVarChar, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CustomerID", System.Data.DataRowVersion.Original, null));
   this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Address", System.Data.SqlDbType.NVarChar, 60, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Address", System.Data.DataRowVersion.Original, null));
   this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_City", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "City", System.Data.DataRowVersion.Original, null));
   this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CompanyName", System.Data.SqlDbType.NVarChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CompanyName", System.Data.DataRowVersion.Original, null));
   this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ContactName", System.Data.SqlDbType.NVarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ContactName", System.Data.DataRowVersion.Original, null));
   this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ContactTitle", System.Data.SqlDbType.NVarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ContactTitle", System.Data.DataRowVersion.Original, null));
   this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Country", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Country", System.Data.DataRowVersion.Original, null));
   this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Fax", System.Data.SqlDbType.NVarChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Fax", System.Data.DataRowVersion.Original, null));
   this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Phone", System.Data.SqlDbType.NVarChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Phone", System.Data.DataRowVersion.Original, null));
   this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_PostalCode", System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "PostalCode", System.Data.DataRowVersion.Original, null));
   this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Region", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Region", System.Data.DataRowVersion.Original, null));
   //
   // sqlConnection1
   //
   this.sqlConnection1.ConnectionString = "workstation id=KEVIN;packet size=4096;user id=sa;initial catalog=Northwind;persis" +
    "t security info=True";
   //
   // sqlInsertCommand1
   //
   this.sqlInsertCommand1.CommandText = @"INSERT INTO Customers(CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax) VALUES (@CustomerID, @CompanyName, @ContactName, @ContactTitle, @Address, @City, @Region, @PostalCode, @Country, @Phone, @Fax); SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax FROM Customers WHERE (CustomerID = @CustomerID)";
   this.sqlInsertCommand1.Connection = this.sqlConnection1;
   this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomerID", System.Data.SqlDbType.NVarChar, 5, "CustomerID"));
   this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CompanyName", System.Data.SqlDbType.NVarChar, 40, "CompanyName"));
   this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactName", System.Data.SqlDbType.NVarChar, 30, "ContactName"));
   this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactTitle", System.Data.SqlDbType.NVarChar, 30, "ContactTitle"));
   this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.NVarChar, 60, "Address"));
   this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@City", System.Data.SqlDbType.NVarChar, 15, "City"));
   this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Region", System.Data.SqlDbType.NVarChar, 15, "Region"));
   this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PostalCode", System.Data.SqlDbType.NVarChar, 10, "PostalCode"));
   this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Country", System.Data.SqlDbType.NVarChar, 15, "Country"));
   this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Phone", System.Data.SqlDbType.NVarChar, 24, "Phone"));
   this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Fax", System.Data.SqlDbType.NVarChar, 24, "Fax"));
   //
   // sqlSelectCommand1
   //
   this.sqlSelectCommand1.CommandText = "SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region," +
    " PostalCode, Country, Phone, Fax FROM Customers";
   this.sqlSelectCommand1.Connection = this.sqlConnection1;
   //
   // sqlUpdateCommand1
   //
   this.sqlUpdateCommand1.CommandText = @"UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName, ContactName = @ContactName, ContactTitle = @ContactTitle, Address = @Address, City = @City, Region = @Region, PostalCode = @PostalCode, Country = @Country, Phone = @Phone, Fax = @Fax WHERE (CustomerID = @Original_CustomerID) AND (Address = @Original_Address OR @Original_Address IS NULL AND Address IS NULL) AND (City = @Original_City OR @Original_City IS NULL AND City IS NULL) AND (CompanyName = @Original_CompanyName) AND (ContactName = @Original_ContactName OR @Original_ContactName IS NULL AND ContactName IS NULL) AND (ContactTitle = @Original_ContactTitle OR @Original_ContactTitle IS NULL AND ContactTitle IS NULL) AND (Country = @Original_Country OR @Original_Country IS NULL AND Country IS NULL) AND (Fax = @Original_Fax OR @Original_Fax IS NULL AND Fax IS NULL) AND (Phone = @Original_Phone OR @Original_Phone IS NULL AND Phone IS NULL) AND (PostalCode = @Original_PostalCode OR @Original_PostalCode IS NULL AND PostalCode IS NULL) AND (Region = @Original_Region OR @Original_Region IS NULL AND Region IS NULL); SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax FROM Customers WHERE (CustomerID = @CustomerID)";
   this.sqlUpdateCommand1.Connection = this.sqlConnection1;
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomerID", System.Data.SqlDbType.NVarChar, 5, "CustomerID"));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CompanyName", System.Data.SqlDbType.NVarChar, 40, "CompanyName"));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactName", System.Data.SqlDbType.NVarChar, 30, "ContactName"));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactTitle", System.Data.SqlDbType.NVarChar, 30, "ContactTitle"));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.NVarChar, 60, "Address"));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@City", System.Data.SqlDbType.NVarChar, 15, "City"));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Region", System.Data.SqlDbType.NVarChar, 15, "Region"));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PostalCode", System.Data.SqlDbType.NVarChar, 10, "PostalCode"));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Country", System.Data.SqlDbType.NVarChar, 15, "Country"));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Phone", System.Data.SqlDbType.NVarChar, 24, "Phone"));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Fax", System.Data.SqlDbType.NVarChar, 24, "Fax"));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CustomerID", System.Data.SqlDbType.NVarChar, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CustomerID", System.Data.DataRowVersion.Original, null));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Address", System.Data.SqlDbType.NVarChar, 60, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Address", System.Data.DataRowVersion.Original, null));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_City", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "City", System.Data.DataRowVersion.Original, null));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CompanyName", System.Data.SqlDbType.NVarChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CompanyName", System.Data.DataRowVersion.Original, null));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ContactName", System.Data.SqlDbType.NVarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ContactName", System.Data.DataRowVersion.Original, null));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ContactTitle", System.Data.SqlDbType.NVarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ContactTitle", System.Data.DataRowVersion.Original, null));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Country", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Country", System.Data.DataRowVersion.Original, null));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Fax", System.Data.SqlDbType.NVarChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Fax", System.Data.DataRowVersion.Original, null));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Phone", System.Data.SqlDbType.NVarChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Phone", System.Data.DataRowVersion.Original, null));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_PostalCode", System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "PostalCode", System.Data.DataRowVersion.Original, null));
   this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Region", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Region", System.Data.DataRowVersion.Original, null));
   //
   // dataSet1
   //
   this.dataSet1.DataSetName = "NewDataSet";
   this.dataSet1.Locale = new System.Globalization.CultureInfo("zh-CN");
   //
   // dataGrid1
   //
   this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    | System.Windows.Forms.AnchorStyles.Right)));
   this.dataGrid1.CanNext = true;
   this.dataGrid1.CanPri = true;
   this.dataGrid1.CurrentPageIndex = 1;
   this.dataGrid1.DataMember = "";
   this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
   this.dataGrid1.Location = new System.Drawing.Point(24, 24);
   this.dataGrid1.Name = "dataGrid1";
   this.dataGrid1.PageCount = 1;
   this.dataGrid1.PageRows = 10;
   this.dataGrid1.RowCount = 1;
   this.dataGrid1.Size = new System.Drawing.Size(720, 208);
   this.dataGrid1.TabIndex = 0;
   //
   // dataColumn1
   //
   this.dataColumn1.ColumnName = "Column1";
   //
   // previousPage
   //
   this.previousPage.Location = new System.Drawing.Point(128, 240);
   this.previousPage.Name = "previousPage";
   this.previousPage.TabIndex = 2;
   this.previousPage.Text = "上一页";
   this.previousPage.Click += new System.EventHandler(this.priPage_Click);
   //
   // nextPage
   //
   this.nextPage.Location = new System.Drawing.Point(224, 240);
   this.nextPage.Name = "nextPage";
   this.nextPage.TabIndex = 3;
   this.nextPage.Text = "下一页";
   this.nextPage.Click += new System.EventHandler(this.nextPage_Click);
   //
   // statusBarPanel
   //
   this.statusBarPanel.Location = new System.Drawing.Point(0, 280);
   this.statusBarPanel.Name = "statusBarPanel";
   this.statusBarPanel.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
                         this.GridInfo,
                         this.GridRows});
   this.statusBarPanel.ShowPanels = true;
   this.statusBarPanel.Size = new System.Drawing.Size(768, 22);
   this.statusBarPanel.TabIndex = 10;
   this.statusBarPanel.Text = "页数";
   //
   // GridInfo
   //
   this.GridInfo.Text = "页数";
   this.GridInfo.Width = 200;
   //
   // GridRows
   //
   this.GridRows.Text = "记录";
   this.GridRows.Width = 2000;
   //
   // lastPage
   //
   this.lastPage.Location = new System.Drawing.Point(320, 240);
   this.lastPage.Name = "lastPage";
   this.lastPage.TabIndex = 4;
   this.lastPage.Text = "最后一页";
   this.lastPage.Click += new System.EventHandler(this.lastPage_Click);
   //
   // firstPage
   //
   this.firstPage.Location = new System.Drawing.Point(32, 240);
   this.firstPage.Name = "firstPage";
   this.firstPage.TabIndex = 1;
   this.firstPage.Text = "第一页";
   this.firstPage.Click += new System.EventHandler(this.firstPage_Click);
   //
   // btnGoPage
   //
   this.btnGoPage.Location = new System.Drawing.Point(632, 239);
   this.btnGoPage.Name = "btnGoPage";
   this.btnGoPage.Size = new System.Drawing.Size(32, 23);
   this.btnGoPage.TabIndex = 7;
   this.btnGoPage.Text = "GO";
   this.btnGoPage.Click += new System.EventHandler(this.btnGoPage_Click);
   //
   // txtGoPage
   //
   this.txtGoPage.Location = new System.Drawing.Point(584, 240);
   this.txtGoPage.Name = "txtGoPage";
   this.txtGoPage.Size = new System.Drawing.Size(24, 21);
   this.txtGoPage.TabIndex = 6;
   this.txtGoPage.Text = "";
   this.txtGoPage.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtGoPage_KeyPress);
   //
   // label2
   //
   this.label2.Location = new System.Drawing.Point(552, 244);
   this.label2.Name = "label2";
   this.label2.Size = new System.Drawing.Size(32, 16);
   this.label2.TabIndex = 8;
   this.label2.Text = "转到";
   //
   // label3
   //
   this.label3.Location = new System.Drawing.Point(608, 244);
   this.label3.Name = "label3";
   this.label3.Size = new System.Drawing.Size(16, 12);
   this.label3.TabIndex = 9;
   this.label3.Text = "页";
   //
   // cmbPage
   //
   this.cmbPage.Location = new System.Drawing.Point(424, 240);
   this.cmbPage.Name = "cmbPage";
   this.cmbPage.Size = new System.Drawing.Size(121, 20);
   this.cmbPage.TabIndex = 5;
   this.cmbPage.Text = "请选择页数";
   this.cmbPage.SelectedIndexChanged += new System.EventHandler(this.cmbPage_SelectedIndexChanged);
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(768, 302);
   this.Controls.Add(this.cmbPage);
   this.Controls.Add(this.txtGoPage);
   this.Controls.Add(this.statusBarPanel);
   this.Controls.Add(this.nextPage);
   this.Controls.Add(this.previousPage);
   this.Controls.Add(this.dataGrid1);
   this.Controls.Add(this.lastPage);
   this.Controls.Add(this.firstPage);
   this.Controls.Add(this.btnGoPage);
   this.Controls.Add(this.label2);
   this.Controls.Add(this.label3);
   this.Name = "Form1";
   this.Text = "Form1";
   ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
   ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
   ((System.ComponentModel.ISupportInitialize)(this.GridInfo)).EndInit();
   ((System.ComponentModel.ISupportInitialize)(this.GridRows)).EndInit();
   this.ResumeLayout(false);

  }
  #endregion

  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());   
  }

  private void loadCombBoxItem()
  {
   for(int i=1; i<=dataGrid1.PageCount; i++)
   {
    cmbPage.Items.Add(i);
   }
  }
  private void showPageStatus()
  {
   previousPage.Enabled=dataGrid1.CanPri;
   nextPage.Enabled=dataGrid1.CanNext;
   GridInfo.Text="第"+dataGrid1.CurrentPageIndex.ToString()+"页/共"+dataGrid1.PageCount.ToString()+"页";
   GridRows.Text="每页"+dataGrid1.PageRows.ToString() +"笔记录"+"/共"+dataGrid1.RowCount.ToString()+"笔记录";
   cmbPage.SelectedIndex = dataGrid1.CurrentPageIndex-1;
  }


  private void priPage_Click(object sender, System.EventArgs e)
  {
   dataGrid1.PriPage();
   showPageStatus();

  }

  private void nextPage_Click(object sender, System.EventArgs e)
  {
   dataGrid1.NextPage();
   showPageStatus();

  }

  private void firstPage_Click(object sender, System.EventArgs e)
  {
   dataGrid1.FirstPage();
   showPageStatus();
  }

  private void lastPage_Click(object sender, System.EventArgs e)
  {
   dataGrid1.LastPage();
   showPageStatus();

  }

  private void btnGoPage_Click(object sender, System.EventArgs e)
  {
   try
   {
    string tempTxtGoPage = txtGoPage.Text.ToString().Trim();
    if(tempTxtGoPage!="")
    {
     int index = Convert.ToInt16(tempTxtGoPage);

     dataGrid1.GoPage(index);
     txtGoPage.Text="";
     showPageStatus();
    }

   }
   catch (Exception ei)
   {
    MessageBox.Show(ei.Message,"Information",MessageBoxButtons.OK,MessageBoxIcon.Warning);
   }

  
  }

  private void cmbPage_SelectedIndexChanged(object sender, System.EventArgs e)
  {
   int index = cmbPage.SelectedIndex+1;
   dataGrid1.GoPage(index);
   showPageStatus();

  }
  
  private void txtGoPage_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  {
   if(e.KeyChar == (char)13) // Convert.ToInt32()e.KeyCahr)
   {
    try
    {
     string tempTxtGoPage = txtGoPage.Text.ToString().Trim();
     if(tempTxtGoPage!="")
     {
      int index = Convert.ToInt16(tempTxtGoPage);

      dataGrid1.GoPage(index);
      txtGoPage.Text="";
      showPageStatus();
     }

    }
    catch (Exception ei)
    {
     MessageBox.Show(ei.Message,"Information",MessageBoxButtons.OK,MessageBoxIcon.Warning);
    }
   }
   if (e.KeyChar == (char) 27)
   {
    txtGoPage.Text="";
   }
  
  }

 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值