当我更改" Long Integer"我在DataGridView中获取DataError(在MS Access数据库中绑定)。字段为但在显示错误后仍然提交我所做的更改,在单元格中输入字母。
如何将单元格的值恢复为之前的有效值?
答案 0 :(得分:2)
正如我在评论中所述:如果数据错误的上下文包含Commit
,则会抛出错误,因为它可能不提交数据。
现在,在您的数据错误处理程序中,调用网格CancelEdit
。
这样的事情:
Private Sub DataGridView1_DataError(sender As Object, e As DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError
If ((e.Context And DataGridViewDataErrorContexts.Commit) = DataGridViewDataErrorContexts.Commit) Then
e.ThrowException = False
Me.DataGridView1.CancelEdit()
Else
e.ThrowException = True
End If
End Sub