4列の単純なdataGridViewがあります。3番目の列の値を合計し、ボタンを押したときに結果を変数に保存したいと思います。私はこのように試しましたが、いつもエラーが発生します
「指定されたキャストは無効です。数値からキャストする場合、値は無限大未満である必要があります」。
PS各セルは基本的にDataGridViewTextBoxColumnです。つまり、値を直接入力できます。
コード:
private void button2_Click(object sender, EventArgs e)
{
Double result = 0;
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
result += (Double)row.Cells[2].Value;
}
this.label13.Text = result .ToString();
}
私は何が欠けていますか?