<script type="text/javascript">
</script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
如何取消对DataGridView的编辑返回编辑前的值?
对DataGridView的某个或者多个单元格做了编辑(没有Update数据库),如何取消对这些单元格的编辑,使得它的值返回编辑前呢?
急,在线等!
__________________________________________________________________________
up
__________________________________________________________________________
如果DataGridView是绑定到dataset的,那保存先前的dataset到一个私有变量,取消编辑就是重新设置DataGridView的datasource
__________________________________________________________________________
如果数据源是DataTable,且没有调用AcceptChanged方法,那么可以调用DataTable.RejectChanges 方法来取消更改。
__________________________________________________________________________
晕死,去年的帖子,还有分得吗?举个例子,如果输入的是“abcd”则弹出提示框,并取消刚才的编辑
VB.NET code
''在CellEndEdit事件中还原,不过只能针对一个,不能针对一批,by guoruixing
Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
If DataGridView1.CurrentCell.Value.ToString = "abcd" Then
MsgBox("错误")
DataGridView1.CancelEdit() ''取消刚才的编辑,by guoruixing
Exit Sub
End If
End Sub
__________________________________________________________________________
如何取消对DataGridView的编辑返回编辑前的值?
对DataGridView的某个或者多个单元格做了编辑(没有Update数据库),如何取消对这些单元格的编辑,使得它的值返回编辑前呢?
急,在线等!
__________________________________________________________________________
up
__________________________________________________________________________
如果DataGridView是绑定到dataset的,那保存先前的dataset到一个私有变量,取消编辑就是重新设置DataGridView的datasource
__________________________________________________________________________
如果数据源是DataTable,且没有调用AcceptChanged方法,那么可以调用DataTable.RejectChanges 方法来取消更改。
__________________________________________________________________________
晕死,去年的帖子,还有分得吗?举个例子,如果输入的是“abcd”则弹出提示框,并取消刚才的编辑
VB.NET code
''在CellEndEdit事件中还原,不过只能针对一个,不能针对一批,by guoruixing
Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
If DataGridView1.CurrentCell.Value.ToString = "abcd" Then
MsgBox("错误")
DataGridView1.CancelEdit() ''取消刚才的编辑,by guoruixing
Exit Sub
End If
End Sub
__________________________________________________________________________