社区
C#
帖子详情
datagirdview的求和问题
chaye12
2008-07-10 10:23:32
我的datagridview是有N列,由N个数据表通过联合查询以及自定义的方式组合成的,我想在最后加上一列,这列的值为前面几列的数值的和,列数不确定,因为列数可能会增多,请问该如何去做?
...全文
65
2
打赏
收藏
datagirdview的求和问题
我的datagridview是有N列,由N个数据表通过联合查询以及自定义的方式组合成的,我想在最后加上一列,这列的值为前面几列的数值的和,列数不确定,因为列数可能会增多,请问该如何去做?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
wocow2316
2008-07-10
打赏
举报
回复
把datagridview 和一个DataSet 绑定
改变 DataSet 的值就可以
Maxlusune
2008-07-10
打赏
举报
回复
double[] sum = new double[14];
protected void exGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[11].Visible = false;
}
if (e.Row.RowType == DataControlRowType.DataRow )//如果行类型是"数据行"
{
sum[0] += double.Parse(e.Row.Cells[2].Text);
sum[2] += double.Parse(e.Row.Cells[3].Text);
sum[3] += double.Parse(e.Row.Cells[4].Text);
sum[4] += double.Parse(e.Row.Cells[5].Text);
sum[5] += double.Parse(e.Row.Cells[6].Text);
sum[6] += double.Parse(e.Row.Cells[7].Text);
sum[7] += double.Parse(e.Row.Cells[8].Text);
sum[8] += double.Parse(e.Row.Cells[9].Text);
sum[9] += double.Parse(e.Row.Cells[10].Text);
sum[10] += double.Parse(e.Row.Cells[11].Text);
e.Row.Cells[12].Text = e.Row.Cells[11].Text;
e.Row.Cells[11].Visible = false;
sum[11] += double.Parse(e.Row.Cells[13].Text);
sum[12] += double.Parse(e.Row.Cells[14].Text);
sum[13] += double.Parse(e.Row.Cells[15].Text);
}
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[0].Text = "合计:";
e.Row.Cells[2].Text = sum[0].ToString();
e.Row.Cells[3].Text = sum[2].ToString();
e.Row.Cells[4].Text = sum[3].ToString();
e.Row.Cells[5].Text = sum[4].ToString();
e.Row.Cells[6].Text = sum[5].ToString();
e.Row.Cells[7].Text = sum[6].ToString();
e.Row.Cells[8].Text = sum[7].ToString();
e.Row.Cells[9].Text = sum[8].ToString();
e.Row.Cells[10].Text = sum[9].ToString();
e.Row.Cells[11].Text = sum[10].ToString();
e.Row.Cells[11].Visible = false;
((TextBox)e.Row.Cells[12].FindControl("tb122")).Visible = true;
e.Row.Cells[13].Text = sum[11].ToString();
e.Row.Cells[14].Text = sum[12].ToString();
e.Row.Cells[15].Text=sum[13].ToString();
}
}
datagridview自动
求和
本篇将详细介绍如何在`DataGridView`中实现类似Excel的自动
求和
功能。 首先,我们需要理解`DataGridView`的基本用法。它是一个控件,通常用于Windows Forms应用程序,可以用来显示二维表格数据。我们可以通过代码...
c# datagridview 行合计
为了实现行合计,我们需要遍历所有数据行,对指定列进行
求和
操作。 1. **创建合计行** - 在`DataGridView`的最后添加一个新的行。这可以通过`DataGridView.Rows.Add()`方法实现,创建一个`DataGridViewRow`对象,...
winform DataGridView 合计行控件
在Windows Forms(Winform)开发环境中,`DataGridView`控件是一种常用的数据展示工具,它可以方便地展示表格数据并进行交互。在某些应用中,我们可能需要在`DataGridView`的底部添加一个总计行,来显示列数据的总和...
datagridview带合计功能
DataGridView带合计功能实现 DataGridView 是一个常用的网格控件,用于显示和编辑数据。然而,DataGridView 并不提供直接的合计功能,这使得开发者需要自己编写代码来实现合计功能。下面是实现 DataGridView 带合计...
DataGridView底部合计行
可以使用`foreach`循环遍历数据源,累加每个需要
求和
的列的值,然后将结果赋值给总计行对应的单元格。 3. **定位总计行**:确保总计行始终位于数据的最后一行,可以监听`DataGridView.DataSource`属性的变化或者...
C#
111,120
社区成员
642,537
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章