先来说下我增加固定行的方法,我是重写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);
        }
如果有其他朋友有更好的方法的,欢迎在这里分享!