0

Dear Friends
i have problem with sum of the value of Datagridview.
please chek code.

 private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            this.dataGridView1.Rows[e.RowIndex].Cells["Column1"].Value = (e.RowIndex + 1).ToString();
            //--------------------for SUM-------------------
            int sum = 0;
            for(int i = 0; i < dataGridView1.Rows.Count-1; ++i)
            {
             sum =sum+int.Parse(dataGridView1.Rows[i].Cells[12].Value.ToString());
            }
            textBox23.Text = sum.ToString();
           }

when i put cell[13] which is quantity and simple degit (For example 5 etc) it works properly and when i put cell[12] which is value (for Example 12.52 etc) i am geting error.
"

An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code

please help me....
"

1
Contributor
1
Reply
8
Views
3 Weeks
Discussion Span
Last Post by zebnoon1
0

thx Friends i soved it to put double data type

double sum = 0;
            for(int i = 0; i < dataGridView1.Rows.Count-1; ++i)
            {
             sum =sum+double.Parse(dataGridView1.Rows[i].Cells[12].Value.ToString());
            }
            textBox23.Text = sum.ToString();
           }
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.