Groups | Blog | Home
all groups > dotnet windows forms databinding > july 2004 >

dotnet windows forms databinding : Howto discard changes and revert?


Gavin Jacobs
7/5/2004 6:43:48 PM
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
7/5/2004 10:35:09 PM
Call the .RejectChanges method of the underlying dataset if you want to undo
everything.

--
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
[quoted text, click to view]

Gavin Jacobs
7/6/2004 8:18:08 AM
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.


[quoted text, click to view]

Gavin Jacobs
7/6/2004 7:24:49 PM
Here's the ticket:
Me.BindingContext(DsData1, "Platform").CancelCurrentEdit()

[quoted text, click to view]

AddThis Social Bookmark Button