Ke *_*Vin 16 c# loops datagridview
如何循环每行readed?在我的代码中,由于产品ID相同,行不会绑定到下一行,因此datagridview不会移动到新行,它仍然在同一行并覆盖价格(对于某些产品,我有两个价格) .如何循环它以显示相同的productID但它有不同的价格.
EX:1汉堡包含2个价格汉堡包:1美元和2美元,当我得到数据循环它,重新应该有2行相同的产品,但不同的价格.这该怎么做?下面是我的代码
productID = odr["product_id"].ToString();
quantity = Double.Parse(odr["quantity"].ToString());
//processing data...
key = productID.ToString();
if (key != key_tmp)
{
//update index...
i++;
//updating variable(s)...
key_tmp = key;
}
if (datagridviews.Rows[i].Cells["qty"].Value != null) //already has value...
{
currJlh = Double.Parse(ddatagridviews.Rows[i].Cells["qty"].Value.ToString());
}
else //not yet has value...
{
currQty = 0;
}
currQty += qty;
//show data...
datagridviews.Rows[i].Cells["price"].Value = cv.toAccountingCurrency_en(Double.Parse(odr["item_price"].ToString()));
MessageBoxes.Show(i.ToString());
MessageBoxes.Show(datagridviews.Rows[i].Cells["price"].Value.ToString()); // in here there is two price that looped but won't showed in datagridviews
Run Code Online (Sandbox Code Playgroud)
帮帮我 :)
Edp*_*per 62
您可以循环DataGridView使用Rows属性,例如:
foreach (DataGridViewRow row in datagridviews.Rows)
{
currQty += row.Cells["qty"].Value;
//More code here
}
Run Code Online (Sandbox Code Playgroud)