Datagridview First Rows Not Consider or Skip

260 pts.
Tags:
C#
DataGridView
Visual Studio
Visual Studio 2005
VS 2005
There is some mistake from my previous question hence once again repeat it.
My problem is on datagridview i have populate combobox and amount column. and ColumnHeader/RowHeaderVisible property set to false. I have coding as below.
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);
            }
        }
My problem is total not counted from begining of the column's rows "ammount".
e.g...
1st rows         column value=12
2nd rows        column value=12
3rows            column value= 12
total of column shows is 24 where as actual columns value is 36.
I think first rows column's total not consider or skip. how to solve it.


Software/Hardware used:
C#, VS-2005

Answer Wiki

Thanks. We'll let you know when a new response is added.

The Best Solution is:
<pre>

private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e)
{
decimal sum = 0.00m;

for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1[1, i].Value != DBNull.Value)
{
sum = sum + Convert.ToDecimal(dataGridView1[1, i].Value);
textBox1.Text = sum.ToString(“f2″);

}

}
}
</pre>

It solved the problem.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following