问题描述
如何循环读取的每一行?在我的代码中,由于相同的 productID,该行不会绑定到下一行,因此 datagridview 不会移动到新行,它仍然在同一行并覆盖价格(对于某些产品,我有两个价格).如何循环显示相同的产品 ID 但价格不同.
How to loop each row that readed? in my code, the row won't bind to next row because of the same productID, so the datagridview won't move to new row, it still in the same row and overwrite the price (for some product, i have two price). How to loop it to show the same productID but it have different price.
EX : 1 个汉堡有 2 个价格汉堡包:1 美元和 2 美元当我通过循环获取数据时,结果应该有 2 行,产品相同但价格不同.这该怎么做?下面是我的代码
EX : 1 Hamburger have 2 priceHamburger : $1 and $2when i get the data with looping it, the resould shoult be have 2 Row with same product but different price. How to do this? below is my code
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
帮帮我:)
推荐答案
您可以使用 Rows
属性循环遍历 DataGridView
,例如:
You could loop through DataGridView
using Rows
property, like:
foreach (DataGridViewRow row in datagridviews.Rows)
{
currQty += row.Cells["qty"].Value;
//More code here
}
这篇关于循环datagridview中的每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!