I am trying to calculation on datagridview as below
Expand|Select|Wrap|Line Numbers
- private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)
- {
- double dd = 1.768901;
- dd = Convert.ToDouble(dd.ToString("f2"));
- DataGridViewCellStyle fixedstyle =
- new DataGridViewCellStyle();
- fixedstyle.Format = "f2";
- dataGridView1.Columns[1].DefaultCellStyle =fixedstyle;
- try
- {
- decimal sum = 0.00m;
- for (int i = 0; i < dataGridView1.Rows.Count - 1;i++)
- if (dataGridView1[1, i].Value != DBNull.Value)
- {
- sum=sum Convert.ToDecimal(dataGridView1[1,i].Value);
- label12.Text = sum.ToString("f2");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
e.g. :-
1st rows column value=12
2nd rows column value=12
3rd rows column value=12
The total shows 24 where actual totals is 36.
I think the datagridview skip first rows. How can i solve it?.
Note:- I set ColumnHeaderVisible property set to false.