110,533
社区成员
发帖
与我相关
我的任务
分享
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;
}