title: How to set value of a DataGridView Cell programatically?
body: <p>I am trying to clear the cell if certain conditions are met. But its not working. </p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code> Private Sub DataGridView1_CellLeave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave
          Dim laspac As Int16 = DataGridView1.Columns("LASPAC").Index
  
          If e.ColumnIndex = laspac And DataGridView1.Rows(e.RowIndex).Cells("CType").Value.ToString.Trim() = "B" Then
              Dim B_LASPAC As DataGridViewCell = DataGridView1.Rows(e.RowIndex).Cells("LASPAC")
              Dim A_LASPAC As DataGridViewCell = DataGridView1.Rows(e.RowIndex - 1).Cells("LASPAC")
              If B_LASPAC.Value.ToString.Trim.Length &lt;&gt; 0 Then
  
                  If Convert.ToDecimal(B_LASPAC.Value) + Convert.ToDecimal(A_LASPAC.Value) &gt; 0 Then
  
                      B_LASPAC.Value = ""
  
  
                  End If
              End If
  
  
          End If
      End Sub
  </code></pre>