如何将产品的数量乘以价格,从而在数据网格视图中给出总和值。支付值的数量应为40,而不是屏幕截图中所示的20,因为第一项的数量为2。
private void dgv_order_CellClick(object sender, DataGridViewCellEventArgs e)
{
int ind = e.RowIndex;
DataGridViewRow selectedRows = dgv_order.Rows[ind];
txt_order.Text = selectedRows.Cells[0].Value.ToString();
cls.select_order1(dataGridView2, txt_order.Text);
int sum = 0;
for (int i = 0; i < dataGridView2.Rows.Count; ++i)
{
sum += Convert.ToInt32(dataGridView2.Rows[i].Cells[3].Value);
}
lblamount.Text = sum.ToString();
}
这是我用于在左侧数据网格视图中选择订单ID的代码,并且我还将其用于金额的总和。
谢谢
答案 0 :(得分:4)
private void dgv_order_CellClick(object sender, DataGridViewCellEventArgs e)
{
int ind = e.RowIndex;
DataGridViewRow selectedRows = dgv_order.Rows[ind];
txt_order.Text = selectedRows.Cells[0].Value.ToString();
cls.select_order1(dataGridView2, txt_order.Text);
int sum = 0;
for (int i = 0; i < dataGridView2.Rows.Count; ++i)
{
sum += (Convert.ToInt32(dataGridView2.Rows[i].Cells[3].Value) * Convert.ToInt32(dataGridView2.Rows[i].Cells[2].Value));
}
lblamount.Text = sum.ToString();
}