2

当用户取消选中 datagridview 行的复选框时,显示消息框,如果用户回答是,则删除该行,如果用户回答否,则我需要重新选中该复选框。但是它实际上并没有检查,除非我之后单击 datagridview 上的任何位置。有什么想法可以让 dgv 更新吗?

Private Sub DataGridView2_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2.CellValueChanged

  If e.RowIndex <> -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
4

1 回答 1

5

而不是Invalidate(),请尝试调用RefreshEdit(),如下所示:

Else
  row.Cells(0).Value = True
  DataGridView2.RefreshEdit()
End If
于 2012-06-05T18:19:27.927 回答