簡體   English   中英

我該如何計算總和。 dataGridView 列中的值?

[英]How can I calculate the sum. of the values in a dataGridView column?

如何計算 integer 和存儲在 dataGridView 列中的浮點值的總和,單擊按鈕並將顯示存儲在文本框中?

int sum = 0;

foreach (DataGridViewRow row in dataGridView.Rows)
{
    //here 0 is the index of columns you want to get values from 
    // you can also use column name instead of index
    sum += (int) row.Cells[0].Value;
}

//for showing the user message box
MessageBox.Show("Sum of all the values is {0}", sum.ToString());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM