Akemi Chou

Akemi Chou

  • NA
  • 13
  • 8.8k

Total SUM of cells in datagridview

Jun 29 2014 4:36 AM
I have two datagrids in my form. The first one already have values and the other one is empty in which what has been selected in the first one will be added into the other one. My problem is while I am adding multiple items with prices * quantity of a product the total amount of it is not correct base on the cell of summation (specifically in Cell[7]). Here's my Code. for more details see the image http://i57.tinypic.com/scurkm.jpg

  private void txtQuantity_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
              
                
                int quantity = Convert.ToInt32(txtQuantity.Text);
                double totalProd = price * quantity;
              
                dr["Total"] = totalProd;
                
            dr["Quantity"] = quantity;
                
            
                for (int i = 0; i < gridViewProduct_Transac.Rows.Count; i++)
                {
                    sum += Convert.ToDouble(gridViewProduct_Transac.Rows[i].Cells[7].Value);
                  

                }
                
                double total = sum;
               
                lblSubtotal.Text = total.ToString("#,##0.##");
                lblTotalAmount.Text = total.ToString("#,##0.##");
                lblTotal.Text = total.ToString("#,##0.##");
                cboSearchBy.Focus();
                txtQuantity.Text = "";
               
                gridViewProduct_Transac.DataSource = dt;
            }
        }

Answers (1)