Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello.
i have datagridview with 'cCommonPrice' cell. im trying to label.text show sum of date in this cell

this my code
private void btnSell_Click(object sender, EventArgs e)
{

    if (Program.myList.Contains(txtBarCode.Text))
    {
        SelectProduct(txtBarCode.Text);
    }

    for (int i = 0; i < dgvProducts.Rows.Count; i++)
    {
        decimal mon = 0;
        decimal comPrice;
        comPrice = (decimal)dgvProducts.Rows[i].Cells["cPrice"].Value;
        mon = comPrice;
        mon = mon + comPrice;
        lblPrice.Text = mon.ToString();
    }
    txtQuantity.ResetText();
    txtBarCode.ResetText();
}


but it does not work
i need help for summing
Im using c# winforms
datagridview source is not sql table
Posted
Comments
shakil0304003 23-Oct-10 13:35pm    
mon = comPrice; mon = mon + comPrice;lblPrice.Text = mon.ToString(); => lblPrice.Text = (comPrice * 2).ToString(); is not it?
shakil0304003 23-Oct-10 13:36pm    
which label you want to show sum of date?
lester555 23-Oct-10 13:43pm    
lblPrice is for showing sum

1 solution

I think there is some problem in your code. Write something like this
                decimal mon = 0;
                decimal comPrice;

for (int i = 0; i < dgvProducts.Rows.Count; i++)
            {
                try
                {
                comPrice = (decimal)dgvProducts.Rows[i].Cells["cPrice"].Value;
                mon += comPrice;
                }
                catch(Exception e)
                {}
            }
lblPrice.Text = mon.ToString();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900