从DataGridView计算

时间:2015-12-04 23:23:42

标签: c# datagridview

我有DataGridView这样:

enter image description here

代码如何从Column Total计算数据并在Label中显示?这意味着Label将显示2650

1 个答案:

答案 0 :(得分:0)

int total= 0;
for (int i = 0; i < dataGridView.Rows.Count; ++i)
{
    sum += Convert.ToInt32(dataGridView.Rows[i].Cells[x].Value); //x=column index 
}
label.text = sum.ToString();