title: Toggle CheckBox Cell in DataGridView Programmatically
body: <p>When user unchecks the checkbox for the datagridview row, messagebox displayed, if the user answers yes the row is deleted, if the user answers no then I need to re-check the check box. however it doesn't actually check unless i click anywhere on the datagridview afterwards. Any ideas to get the dgv to updated?</p>
  
  <pre><code>Private Sub DataGridView2_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2.CellValueChanged
  
    If e.RowIndex &lt;&gt; -1 Then
      Dim row As DataGridViewRow = DataGridView2.Rows(e.RowIndex)
      If e.ColumnIndex = 0 Then
        If row.Cells(0).Value = False Then
          If MessageBox.Show("Delete view from database.", "Delete", MessageBoxButtons.YesNo) = DialogResult.Yes Then
            DataGridView2.Rows.RemoveAt(e.RowIndex)
          Else
            row.Cells(0).Value = True
            DataGridView2.Invalidate()
          End If
        End If
      End If
    End If
  End Sub
  
  Private Sub DataGridView2_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles DataGridView2.CurrentCellDirtyStateChanged
    If DataGridView2.IsCurrentCellDirty Then
      DataGridView2.CommitEdit(DataGridViewDataErrorContexts.Commit)
    End If
  End Sub
  </code></pre>