先看看理想的效果.
http://hi.csdn.net/attachment/200912/24/148499_12616267360nta.jpg
重绘(问题一)
http://hi.csdn.net/attachment/200912/24/148499_1261626743i0gC.jpg
重绘(问题二)
http://hi.csdn.net/attachment/200912/24/148499_1261626746RUZY.jpg我把重绘放在了 dataGridView1_RowPostPaint 事件里面.
因为 dataGridView1_ColumnWidthChanged 的时候 ,我才能实现重绘合计行的竖线...问题来了:
     当我拖动(变大) dataGridView1 高度的时候,如图2这个问题
     当我拖动(变小) dataGridView1 高度的时候,如图3这个问题希望高手帮帮忙...

解决方案 »

  1.   

    你用的两个DataGridView吧.不知道你合计栏的那个DataGridView的Parent是原数据的DataGridView还是其上级(表单或容器).首先,如果你对合计栏的这个DataGridView有定义坐标,就先检查坐标计算是否正确,再检查一下anchor属性设置是怎么处理的.再设置一下将合计栏的那个DataGridView置顶(BringToFront()方法).
      

  2.   

    我用的一个DataGridView.如果用2个的话,假如没有横向滚动条的话,统计行就不会出现在当前视线范围的最下面...
      

  3.   

    我的合计栏不是DataGridView,是通过using System.Drawing.画出来的,如果是的话,以上问题都不会出现...但是这样效率低了
      

  4.   

    大致代码如下//统计计算
    private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
    {
    if ( e.RowIndex != -1 )
    {
        using ( Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor), backColorBrush = new SolidBrush(e.InheritedRowStyle.BackColor) )
        {
            using ( Pen gridLinePen = new Pen(gridBrush) )
            {
                //画底色
                Rectangle re = this.ClientRectangle;
                re = new Rectangle(e.RowBounds.Left, this.dataGridView1.Height - 25, getDataGridViewWidth(), 25);
                e.Graphics.FillRectangle(backColorBrush, re);
                e.Graphics.DrawArc(gridLinePen, re, 12, 84);
                e.Graphics.DrawRectangle(gridLinePen, re);
                //  画合计
                e.Graphics.DrawString("合计", this.Font, new SolidBrush(this.dataGridView1.DefaultCellStyle.ForeColor), 5, this.dataGridView1.Height - 21);            //  画横线顶部
                e.Graphics.DrawLine(gridLinePen,
                                    e.RowBounds.Left,
                                    this.dataGridView1.Height - 2,
                                    e.RowBounds.Right,
                                    this.dataGridView1.Height - 2);
                //  画横线底部
                e.Graphics.DrawLine(gridLinePen,
                                    e.RowBounds.Left,
                                     this.dataGridView1.Height - 23,
                                    e.RowBounds.Right,
                                     this.dataGridView1.Height - 23);
                //  画竖线边线
                float _sum = 0;
                int intAllWidth = 0;            if ( dataGridView1.RowHeadersVisible )
                {
                    intAllWidth += dataGridView1.RowHeadersWidth - 1;
                    e.Graphics.DrawLine(gridLinePen,
                                        intAllWidth,
                                        this.dataGridView1.Height - 24,
                                        intAllWidth,
                                        this.dataGridView1.Height - 2);
                }
                for ( int n = 0 ; n < this.dataGridView1.Columns.Count ; n++ )
                {
                    intAllWidth += dataGridView1.Columns[ n ].Width;                e.Graphics.DrawLine(gridLinePen,
                                        intAllWidth,
                                        this.dataGridView1.Height - 24,
                                        intAllWidth,
                                        this.dataGridView1.Height - 2);
                    if ( IsNumeric(this.dataGridView1.Columns[ n ].DataPropertyName) )
                    {
                        for ( int i = 0 ; i < this.dataGridView1.Rows.Count - 1 ; i++ )
                        {
                            _sum += float.Parse(this.dataGridView1.Rows[ i ].Cells[ n ].Value.ToString());
                        }
                        e.Graphics.DrawString(_sum.ToString(), this.Font, new SolidBrush(this.dataGridView1.DefaultCellStyle.ForeColor), intAllWidth - this.dataGridView1.Columns[ n ].Width, this.dataGridView1.Height - 21);
                    }
                }
            }                    
        }
    }
      

  5.   

    if ( e.RowIndex != -1 )
    {
        DataGridView.Refresh(); //先执行这个看看
    }
      

  6.   

    恩 如果DataGridView.Refresh();  方法可以笨的方法.. 简单的说 你这次绘制的最大区域记录下来  下次绘制的时候清除掉.把这个 DataGridView.Refresh();替换成    Graphics.FillRectangle(new SolidBrush(this.BackColor),re); Rectangle re = this.ClientRectangle;re = new Rectangle(e.RowBounds.Left, this.dataGridView1.Height - 25, getDataGridViewWidth(), 25);
    是你定义的最终区域把如果定义成全局变量 private  Rectangle re = new Rectangle ();