DataGridView合计行,与合并行的三个单元格 DataGridView绑定定了数据源,在最底部添加了合计行。1、最后一行合计怎么让其始终显示在最下面,现在排序会将其排到第一行去,该怎么处理?2、“合计”二字想在最后一行第1,2,3列合并,且居中显示,不知道行不行?并控制这3列不能拖动顺序或其他列不能拖到这3列之间? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 分开写DataGridView中只统计每条数据,,最后用个div或table制作显示合计。DataGridView里使用某一种标签如Label绑定需要统计的数据,给Label附上Name属性或Class属性或不附,,反正给个标记属性或直接通过Label,通过JQUERY来查找获取数值,然后统计。OK了啊,至于统计合并几个那就全看你怎么根据DataGridView的样式div出一个不就行了、、 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 }} DataGridView 我看你的方法是用VB写的吧,我是用C#写的程序。 关于设计模式的选择 读取csv档案 C#中怎么从数据库中获取图片路径 C# 用接口取IE访问历史记录 在IIS里面取不到记录. 相对坐标和绝对坐标的怎么转换? c#如何修改ie9的临时文件大小的设置。 64位的系统装能注册 CodeSmith 7 吗? Windows服务错误。 请问谁有一些关于数据绑定和非绑定的文章和讨论? C#实现填写网页表单并提交 c#实现c/s结构,求高手指教 XP→windows 7
DataGridView的样式div出一个不就行了、、
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
}
}