日期:2014-05-17  浏览次数:21244 次

搞定了WINFORM下DataGridView底部固定合计行被最后一行遮挡的问题了,发布到这里以备那些有需要的朋友们参考
先来说下我增加固定行的方法,我是重写DataGridView,给DataGridView添加一个Panel控件,位置当然是DataGridView的底部了,这里具体位置的计算就不再罗嗦了。
  然后重写DataGridView的OnRowPrePaint方法,在每次新行绘制时同时在该行的下面再绘制一个和DataGridView背景相同的空行。代码如下:
  protected override void OnRowPrePaint(DataGridViewRowPrePaintEventArgs e)
  {
  base.OnRowPrePaint(e);
  int iTop = e.RowBounds.Top + e.RowBounds.Height + 1;
  int iHeight = e.RowBounds.Height;
  Rectangle nullRec = new Rectangle(e.RowBounds.Left, iTop, e.RowBounds.Width, iHeight);
  Brush backBrush = new SolidBrush(this.BackgroundColor);
  Graphics tmpG = e.Graphics;
  tmpG.FillRectangle(backBrush, nullRec);
  }
如果有其他朋友有更好的方法的,欢迎在这里分享!

------解决方案--------------------
sf
------解决方案--------------------
高实在是高
------解决方案--------------------
shouchang
------解决方案--------------------
ding
------解决方案--------------------
不错。
------解决方案--------------------
赞扬楼主的分享精神