title: My datagridview cellvalue changed event is not working ..C# & SQL Server 2008
body: <p>There is small bug in my code. My datagridview cell value changed event is not working. When I add any data, rows to the datagrid view is should display the total amount to the textbox which is not working. Can you help me please?</p>
  
  <p>Code:</p>
  
  <pre><code>private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  {
      if (e.ColumnIndex == 5)
          txtNetAmt.Text = CellSum().ToString();
  
      int sum = 0;
  
      for (int i = 0; i &lt; dataGridView1.Rows.Count; ++i)
      {
          sum += Convert.ToInt32(dataGridView1.Rows[i].Cells[5].Value);
      }
  
      txtNetAmt.Text = sum.ToString();
      int DiscountedSum = 0;
  
      for (int i = 0; i &lt; dataGridView1.Rows.Count; ++i)
      {
          DiscountedSum += Convert.ToInt32(dataGridView1.Rows[i].Cells[4].Value);
      }
  
      txtDiscamt.Text = DiscountedSum.ToString();
      int SubTotal = sum + DiscountedSum;
      txtSubTotalamt.Text = SubTotal.ToString();
  }
  </code></pre>
  
  <p>Screenshot:</p>
  
  <p><a href="https://i.stack.imgur.com/j4bf5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j4bf5.jpg" alt="enter image description here"></a></p>