在循环DataGridView的每一行 [英] Looping each row in datagridview

查看:196
本文介绍了在循环DataGridView的每一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何循环readed每一行?在我的代码,该行也不会仍然结合,因为相同的productID的下一行,所以在DataGridView不会移动到新的行,它在同一行中并覆盖价格(对于某些产品,我有两个价) 。它如何循环显示相同的productID,但有不同的价格。

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
当我与它循环获取数据时,resould shoult是有2行与同样的产品,但不同的价格。如何做到这一点?下面是我的代码

EX : 1 Hamburger have 2 price Hamburger : $1 and $2 when 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



帮我出: )

help me out :)

推荐答案

您可以通过 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的每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆