DataGridview Skip The Value Of First Row Column
<p>The dataGridview <strong>first row column</strong> name <strong>amount</strong> is return no value as there is value inserted.</p>

<p><strong>For our Peers' Convenient I draw the table as it's help to answer it better.</strong></p>

<p>my table on dataGridview is as below:  </p>

<pre><code>   private void Form1_Load(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("name",typeof(string));
        dt.Columns.Add("amount",typeof(decimal));
        dataGridView1.DataSource = dt;
        dataGridView1.Columns[1].DefaultCellStyle.Format = "f2";
    }
</code></pre>

<p>Now I prepared the table and my main code is below:</p>

<pre><code>  private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)
    {
        decimal sum = 0.00m;

        for (int i = 0; i &lt; dataGridView1.Rows.Count-1; i++) 
        {
                sum = sum + Convert.ToDecimal(dataGridView1[1, i].Value);
                textBox1.Text = sum.ToString("f2");
        }
    }
</code></pre>

<p>The above code throw Error like <strong>"Object Cannot cast from DBNull to other types".</strong> Even though there is value.</p>

<p>Now Look at to another Code:</p>

<pre><code>private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)
    {
        decimal sum = 0.00m;

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

            }        

        }
    }
</code></pre>

<p>Now this code not throwing any Error but still the problem with it. The problem is when i enter the value on column of <strong>amount</strong> is look like it skip the value of first row's column name <strong>amount</strong>.</p>

<p><strong>e.g....</strong></p>

<p>I enter the value on column name <strong>amount</strong> is below:</p>

<pre><code>1st Row column amount values is = 12
2nd Row column amount values is = 12
3rd Row column amount values is = 12
</code></pre>

<p>Now the total showing in textbox1 is = 24, where as actual total is = 36.</p>

<p>There is going something wrong with coding it shows that dataGridview's first row's column value is not accepted.</p>
