Zeb Muhammad

Zeb Muhammad

  • NA
  • 67
  • 17.9k

Sum of Datagridview.

Jul 28 2017 1:24 AM
Dear Friends
i have problem with sum of the value of Datagridview.
please chek code.
  1. private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
  2. {
  3. this.dataGridView1.Rows[e.RowIndex].Cells["Column1"].Value = (e.RowIndex + 1).ToString();
  4. //--------------------for SUM-------------------
  5. int sum = 0;
  6. for(int i = 0; i < dataGridView1.Rows.Count-1; ++i)
  7. {
  8. sum =sum+int.Parse(dataGridView1.Rows[i].Cells[12].Value.ToString());
  9. }
  10. textBox23.Text = sum.ToString();
  11. }

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

 

Answers (2)