记录DataGird的整行数据之和及动态创建列后赋值和
List<string> num = new List<string>();
try
{
for (int i = 0; i < DataGrid1.Rows.Count - 1; i++)
{
double aa = 0;
for (int j = 1; j < DataGrid1.Columns.Count; j++)
{
double bb = Convert.ToDouble(DataGrid1.Rows[i].Cells[j].Value);
aa += bb;
}
num.Add(aa.ToString());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
/////////////////////////////////////////////////////////////
DataGridViewTextBoxColumn QuantityColumn = new DataGridViewTextBoxColumn();
QuantityColumn.Name = "Quantity";
QuantityColumn.HeaderText = "总计";
QuantityColumn.Width = 100;
QuantityColumn.SortMode = DataGridViewColumnSortMode.Automatic;
dgGoodsSale.Columns.Add(QuantityColumn);
for (int i = 0; i < dgGoodsSale.Rows.Count-1;i++)
{
this.dgGoodsSale.Rows[i].Cells["Quantity"].Value = Convert.ToDouble(num[i]);
}