I have a form bound to a specific row in a table in a dataset. I am trying
to implement Save and Discard buttons. I have the Save button working using
the DataRowView.EndEdit method. For the Discard button I call
DataRowView.CancelEdit. The changes really are canceled, but the user input
is still there. I can't figure out how to get the Textbox to revert to the
previous value. What's the trick?
Here's the code:
Private Sub btnPlatformSave_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnPlatformSave.Click
Dim Row As DataRowView
Row = CType(Me.BindingContext(DsData1, "Platform").Current,
DataRowView)
Row.EndEdit()
btnPlatformSave.Enabled = False
btnPlatformDiscard.Enabled = False
End Sub
Private Sub btnPlatformDiscard_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnPlatformDiscard.Click
Dim Row As DataRowView
Row = CType(Me.BindingContext(DsData1, "Platform").Current,
DataRowView)
Row.CancelEdit()
' Get old values back
btnPlatformSave.Enabled = False
btnPlatformDiscard.Enabled = False
End Sub
William Ryan eMVP - 06 Jul 2004 03:35 GMT
Call the .RejectChanges method of the underlying dataset if you want to undo
everything.

Signature
W.G. Ryan MVP Windows - Embedded
Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
> I have a form bound to a specific row in a table in a dataset. I am trying
> to implement Save and Discard buttons. I have the Save button working using
[quoted text clipped - 24 lines]
> btnPlatformDiscard.Enabled = False
> End Sub
Gavin Jacobs - 06 Jul 2004 12:18 GMT
William,
Unfortunately, that doesn't do it. When I call .RejectChanges, the textbox
still displays the changed value until I navigate away from the record and
then return, and then it shows the previous value (which is what I wanted,
but without the hassle of navigating away and back). In other words, I want
a way to reload the textbox with the values from the unchanged dataset.
> Call the .RejectChanges method of the underlying dataset if you want to undo
> everything.
[quoted text clipped - 30 lines]
> > btnPlatformDiscard.Enabled = False
> > End Sub
Gavin Jacobs - 06 Jul 2004 23:24 GMT
Here's the ticket:
Me.BindingContext(DsData1, "Platform").CancelCurrentEdit()
> I have a form bound to a specific row in a table in a dataset. I am trying
> to implement Save and Discard buttons. I have the Save button working using
[quoted text clipped - 24 lines]
> btnPlatformDiscard.Enabled = False
> End Sub