DataGridView绑定定了数据源,在最底部添加了合计行。1、最后一行合计怎么让其始终显示在最下面,现在排序会将其排到第一行去,该怎么处理?
2、“合计”二字想在最后一行第1,2,3列合并,且居中显示,不知道行不行?并控制这3列不能拖动顺序或其他列不能拖到这3列之间?

解决方案 »

  1.   

    分开写DataGridView中只统计每条数据,,最后用个div或table制作显示合计。DataGridView里使用某一种标签如Label绑定需要统计的数据,给Label附上Name属性或Class属性或不附,,反正给个标记属性或直接通过Label,通过JQUERY来查找获取数值,然后统计。OK了啊,至于统计合并几个那就全看你怎么根据
    DataGridView的样式div出一个不就行了、、
      

  2.   


    using System;
    using System.Collections.Generic;
    using System.Collections;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication6
    {
        public class FormHelper
        {
            #region 添加一行
            public void AddRow(DataGridView dg, string value)
            {
                if (dg.Rows.Count > 1)
                {
                    DelRow(dg, dg.Rows.Count - 1);
                }
                dg.Rows.Add();
                for (int i = 0; i < dg.Columns.Count; i++)
                {
                    dg.Rows[dg.Rows.Count - 1].Cells[i].Value = value;
                }
                dg.CurrentCell = dg.Rows[dg.Rows.Count - 1].Cells[0];
                TotalRow(dg);
            }
            #endregion
            #region 编辑一行
            public void EditRow(DataGridView dg)
            {
                DelRow(dg, dg.Rows.Count - 1);
                TotalRow(dg);  
            }
            #endregion
            #region 删除一行
            public void DelRow(DataGridView dg,int index)
            {
                dg.Rows.Remove(dg.Rows[index]);
            }
            #endregion
            #region 合计行
            public void TotalRow(DataGridView dg)
            {
                dg.Rows.Add();
                DataGridViewRow dgr = dg.Rows[dg.Rows.Count - 1];
                dgr.ReadOnly = true;
                dgr.DefaultCellStyle.BackColor = System.Drawing.Color.Khaki;
                dgr.Cells[0].Value = "合计";
                for (int i = 0; i < dg.Rows.Count - 1; i++)
                {
                    dgr.Cells[3].Value = Convert.ToSingle(dgr.Cells[3].Value) + Convert.ToSingle(dg.Rows[i].Cells[3].Value);
                }
            }
            #endregion
        }
    }
      

  3.   

    DataGridView 
      

  4.   

    我看你的方法是用VB写的吧,我是用C#写的程序。