社区
C#
帖子详情
datagirdview的求和问题
chaye12
2008-07-10 10:23:32
我的datagridview是有N列,由N个数据表通过联合查询以及自定义的方式组合成的,我想在最后加上一列,这列的值为前面几列的数值的和,列数不确定,因为列数可能会增多,请问该如何去做?
...全文
54
2
打赏
收藏
datagirdview的求和问题
我的datagridview是有N列,由N个数据表通过联合查询以及自定义的方式组合成的,我想在最后加上一列,这列的值为前面几列的数值的和,列数不确定,因为列数可能会增多,请问该如何去做?
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用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应用程序,可以用来显示二维表格数据。我们可以通过代码...
winform DataGridView 合计行控件
在Windows Forms(Winform)开发环境中,`DataGridView`控件是一种常用的数据展示工具,它可以方便地展示表格数据并进行交互。在某些应用中,我们可能需要在`DataGridView`的底部添加一个总计行,来显示列数据的总和...
c#中向DataGridView控件中添加合计、平均值、最大值、最小值
这可以通过遍历`DataGridView.Rows`集合,对每个数值单元格(`DataGridViewCell`)的`Value`属性
求和
来实现。但是,如果使用了`AX.SubDataGrid.dll`,可能有更便捷的方法,例如调用特定的API函数来自动添加合计行。 ...
Winform系列——好看的DataGridView折叠控件
在本文中,我们将深入探讨如何在Windows Forms(Winform)应用程序中实现一个美观且功能丰富的DataGridView折叠控件。这个控件允许用户以折叠的方式查看和管理大量数据,从而提高用户体验和界面的整洁度。我们将主要...
C# winform datagridview 动态列值计算_datagridview动态列值计算_fairlyfl7_winf
WinForms是.NET Framework提供的一种用于构建图形用户界面(GUI)的工具集,它包含丰富的控件,如DataGridView,用于显示和操作表格数据。本篇文章将深入探讨如何在C# WinForm应用程序中实现DataGridView的动态列值...
C#
111,093
社区成员
642,554
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章