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....
"

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();
           }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.