如何循环读取的每一行?在我的代码中,由于相同的productID,该行不会绑定到下一行,因此datagridview不会移至新行,它仍位于同一行并覆盖价格(对于某些产品,我有两个价格) 。如何循环显示相同的productID,但价格不同。
例如: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
帮帮我 :)
您可以遍历DataGridView
使用Rows
属性,例如:
foreach (DataGridViewRow row in datagridviews.Rows)
{
currQty += row.Cells["qty"].Value;
//More code here
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句