ColumIndex 列index
public static Decimal DGCellSumToDecimal(DataGridView DataGD, int ColumIndex)
{
decimal totalprice = 0.0m;
Decimal Dtotal = 0;
if (DataGD.Rows.Count > 0)
{
for (int i = 0; i < DataGD.Rows.Count - 1; i++)
{
totalprice += Convert.ToDecimal(DataGD.Rows[i].Cells[ColumIndex].Value.ToString());
}
Dtotal = totalprice;
}
return Dtotal;
}
调用:如计算dataGridView1第四列的值
decimal conut =DGCellSumToDecimal(dataGridView1, 3)