Quoting each row in a datagridview

How to loop each read line? in my code, the row will not be attached to the next row due to the same product identifier, so the datagridview will not move to a new row, it is still in the same row and overwrites the price (for some product I have two prices), How to loop him to show the same product id, but it has a different price.

EX: 1 Hamburger has 2 prices Hamburger: $ 1 and $ 2 when I get data with a loop on them, shoult will have 2 rows with the same product, but with a different price. How to do it? 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:)

+7
c # loops datagridview
source share
2 answers

You can execute a DataGridView loop using the Rows property, for example:

 foreach (DataGridViewRow row in datagridviews.Rows) { currQty += row.Cells["qty"].Value; //More code here } 
+37
source share

Best for me was:

  private void grid_receptie_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { int X = 1; foreach(DataGridViewRow row in grid_receptie.Rows) { row.Cells["NR_CRT"].Value = X; X++; } } 
-one
source share

All Articles