Undoing record changes

I have a list box and a set of text boxes bound to a dataSource (or something like that:-) The list box is used to navigate. Everything works just find - add, delete, edit, etc.

HOWEVER, I haven't quite figured out how to make the undo button work:-( It will have two modes.
1. If not editing then undo all changes since last Accept. (You can delete or edit multiple records and undo all the changes. I still have to put in code to allow moving record to accept changes as an option to hitting the accept button.)

2. If editing then undo just the changes to the currently being editted thingie. (I'm being vague here because perhaps if i knew exactly what was being editted I wouldn't be having this problem.) Undo i this mode needs to restore all the text boxes to the state preferably before the current edit, but baring that the state after the last Accept.

#1 works just fine. How do I make #2 work?

Regards,
Al

[936 byte] By [AlChristoph] at [2008-2-10]
# 1
Hi,
Take a look on the DataRow.RejectChanges() method...
cheers,
Paul June A. Domag
PaulDomag at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
Al Christoph wrote:
I have a list box and a set of text boxes bound to a dataSource (or something like that:-) The list box is used to navigate. Everything works just find - add, delete, edit, etc.

HOWEVER, I haven't quite figured out how to make the undo button work:-( It will have two modes.
1. If not editing then undo all changes since last Accept. (You can delete or edit multiple records and undo all the changes. I still have to put in code to allow moving record to accept changes as an option to hitting the accept button.)

2. If editing then undo just the changes to the currently being editted thingie. (I'm being vague here because perhaps if i knew exactly what was being editted I wouldn't be having this problem.) Undo i this mode needs to restore all the text boxes to the state preferably before the current edit, but baring that the state after the last Accept.

#1 works just fine. How do I make #2 work?

Regards,
Al


Al,

For #2, you will have to store the state of the row before you enter the edit state. Once you know you have entered your "edit" state (before changes have been committed), if you cancel, then you can just restore the values that you stored before to the row.

The data row only knows in a general sense if there is an edit, not if multiple edits since the last time it was accepted have been performed.

Hope this helps.

- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

casperOne at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
You can handle the RowChanging/RowChanged events to validate that an acceptable change happened. If it didn't, you can undo the change using the above suggestion - Row.RejectChanges.



Private Sub dvdsDataTable_RowChanging(ByVal sender As Object, ByVal e As System.Data.DataRowChangeEventArgs) Handles dvdsDataTable.RowChanging

Dim myDvdRow As MyMovieCollection1.DVDCollectionDataSet.DVDsRow = e.Row

'doing some validation on the change

If myDvdRow.Description <> "" Then

'valid

Else

'invalid so undo'ing row changes

myDvdRow.RejectChanges()

End If

End Sub



hth,
Paul

PaulYuk_MS at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...