datagridview 汇总

footprint2008 2009-05-21 09:40:02
winform C# 想在datagridview 的最后一行加入汇总,如出库汇总,如何实现?
...全文
184 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
footprint2008 2009-05-21
  • 打赏
  • 举报
回复
我想要一总比较简单的方式.
因为有N多这样的表要汇总.
zealot1021 2009-05-21
  • 打赏
  • 举报
回复
for循环相加呗,楼主自己应该能想到的
yangjiang113 2009-05-21
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 surlew 的回复:]
C# code
public static void 总计(DataGridView ucgrd, string col)
{
for (int i = 0; i < ucgrd.Columns.Count; i++)
{
ucgrd.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}

//总计
string[] str总计 = clsString.Split空格(col);

ucgrd.RowCount = ucgrd.RowCount + 1;


[/Quote]

很好
surlew 2009-05-21
  • 打赏
  • 举报
回复

public static void 总计(DataGridView ucgrd, string col)
{
for (int i = 0; i < ucgrd.Columns.Count; i++)
{
ucgrd.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}

//总计
string[] str总计 = clsString.Split空格(col);

ucgrd.RowCount = ucgrd.RowCount + 1;

//在ucgrd.RowCount-1行插入总计行
for (int i = 0; i < str总计.Length - 1; i++)
{
int 列 = clsC.Cint(str总计[i]);
//遍历整个表,相加得总计和
for (int 行 = 0; 行 < ucgrd.RowCount - 1; 行++)
{
double 数量1 = 0, 数量2 = 0;
if (ucgrd.Rows[ucgrd.RowCount - 1].Cells[列].Value != null)
{
数量1 = clsC.Cdbl(ucgrd.Rows[ucgrd.RowCount - 1].Cells[列].Value.ToString());
}
if (ucgrd.Rows[行].Cells[列].Value != null)
{
数量2 = clsC.Cdbl(ucgrd.Rows[行].Cells[列].Value.ToString());
}
ucgrd.Rows[ucgrd.RowCount - 1].Cells[列].Value = 数量1 + 数量2;
}
}

ucgrd.Rows[ucgrd.RowCount - 1].Cells[0].Value = "";
ucgrd.Rows[ucgrd.RowCount - 1].Cells[1].Value = "总计";

//颜色
ucgrd.Rows[ucgrd.RowCount - 1].DefaultCellStyle.BackColor = Color.PaleGoldenrod;

}

这是我写的一个总计小方法,
将datagridview和自己想要总计的列号传进去就可以了
footprint2008 2009-05-21
  • 打赏
  • 举报
回复
单个页面的汇总
-无-为- 2009-05-21
  • 打赏
  • 举报
回复
单个页面的汇总 好搞


但是如果你要分页的话,我就不知道了
footprint2008 2009-05-21
  • 打赏
  • 举报
回复
to surlew :
报错..
错误 1 当前上下文中不存在名称“clsString” E:\桌面\1\newstock\newstock\cls\sumdatagridview.cs 19 30 newstock
错误 2 当前上下文中不存在名称“clsC” E:\桌面\1\newstock\newstock\cls\sumdatagridview.cs 26 25 newstock
错误 3 当前上下文中不存在名称“clsC” E:\桌面\1\newstock\newstock\cls\sumdatagridview.cs 33 31 newstock
错误 4 当前上下文中不存在名称“clsC” E:\桌面\1\newstock\newstock\cls\sumdatagridview.cs 37 31 newstock
错误 5 当前上下文中不存在名称“Color” E:\桌面\1\newstock\newstock\cls\sumdatagridview.cs 47 73 newstock
hecker728 2009-05-21
  • 打赏
  • 举报
回复
sql语句,直接返回

要么就只有一行一行的加了
bbb332 2009-05-21
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 surlew 的回复:]
C# code
public static void 总计(DataGridView ucgrd, string col)
{
for (int i = 0; i < ucgrd.Columns.Count; i++)
{
ucgrd.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}

//总计
string[] str总计 = clsString.Split空格(col);

ucgrd.RowCount = ucgrd.RowCount + 1;


[/Quote]

学习了

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧