数据网格视图中的数学计算 [英] Math calculation in datagrid view
本文介绍了数据网格视图中的数学计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在datagridview中有超过50行的数据现在我需要将两个单元格相乘并存储在第3个单元格中的前10或20.平衡行需要添加两个单元格并存储在第3个单元格中
我尝试过的事情:
i have a more than 50 rows of data in datagridview now i need to multiply a two cell and store in a 3rd cell for first 10 or 20. balance rows are need to add a two cell and store in a 3rd cell
What I have tried:
<pre>foreach (DataGridViewRow row in dataGridView1.Rows)
{
dg = row.Index;
for (dg = 1; dg < 10; dg++)
{
row.Cells[dataGridView1.Columns["c"].Index].Value = (Convert.ToDouble(row.Cells[dataGridView1.Columns["a"].Index].Value)) * (Convert.ToDouble(row.Cells[dataGridView1.Columns["b"].Index].Value));
//dataGridView1.Rows[dg].Cells[2].Value = ((Convert.ToDouble(dataGridView1.Rows[dg].Cells[1].Value)) * (Convert.ToDouble(dataGridView1.Rows[dg].Cells[0].Value))).ToString();
}
}
推荐答案
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells["A"].Value == null)
{
break;
}
double a = Convert.ToDouble(row.Cells["A"].Value.ToString());
double b = Convert.ToDouble(row.Cells["B"].Value.ToString());
row.Cells["C"].Value = (a * b).ToString();
}
这篇关于数据网格视图中的数学计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文