日期:2012-06-07  浏览次数:20572 次

工作需要,要实现windows应用程序中用的datagrid具有分页功能,不知道ms怎么想的,asp.net的datagrid有这样的功能,为什么不在winForm的datagrid里面提供这样的功能,还得让我费这么大劲儿来重写这个控件,真是麻烦。

首先,我们要做一个类来继承系统的datagrid:

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

 

namespace oilx.PagingDataGrid

{

public class PagingDataGrid : DataGrid

{

  // 声明一些必要的全局变量。

private System.ComponentModel.Container components = null;

 

                      /// <summary>

                      ///                  

/// </summary>

                      private const int MarkerWith = 14;

 

                      /// <summary>

                      ///

                      /// </summary>

                      private Point      _pointTopLeft; 

 

                      /// <summary>

                      ///

                      /// </summary>

                      private int _row = 1;

 

                      //

                      private int _rowNumberFigure = 0;

                      private bool _zeroPadding = false;

 

                      /// <summary>

                      ///

                      /// </summary>

                      private string _rowHeaderCaption = String.Empty;

 

                      /// <summary>