【发布时间】:2018-02-27 16:49:46
【问题描述】:
我需要获取一行中两列的所有值并将其相乘并为每一行添加两列的乘积
foreach (DataGridViewRow row in dataGridView2.Rows)
{
int currPrice = Convert.ToInt32(row.Cells[1].Value.ToString());
int currQuan = Convert.ToInt32(row.Cells[2].Value.ToString());
int newPrice = currPrice++;
int newQuan = currQuan++;
int newTotal = newPrice * newQuan;
textBox4.Text = newTotal.ToString();
}
它有效,但仅在选定的行中有效。
例如在数据网格中我有 2 行
第一行的价格是 10,数量是 20,所以我需要得到它的产品并对另一行做同样的事情,一旦所有行都完成了,它应该把它全部加起来/得到总和
我的行数不是预先确定的,所以它应该是动态的,我应该怎么做?
【问题讨论】:
标签: c# loops for-loop datagridview foreach