Click here to Skip to main content
14,271,998 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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();
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100