I think you might want to look into windows forms databinding in either MSDN
or on Codeproject. You need to to detect changes in the underlying
datasource, not the form itself. For example, datatables have built in
events that fire when column values change.
http://msdn.microsoft.com/en-us/library/system.data.datatable.columnchanged.aspx
And built in methods to cancel changes made by the user:
http://msdn.microsoft.com/en-us/library/system.data.datatable.rejectchanges.aspx
If you are directly binding business objects to the form, then you can build
dirty detection into your classes. If you are using business objects then
also investigate System.ComponentModel.Bindinglist(of T) as it's a real fast
track to getting lists of your business classes bindable.
If you want multiple undo, the strategy is to deepcopy the underlying object
with each edit and push it on a stack. System.Collections.Generic.Stack(Of
T) is great for this.
http://msdn.microsoft.com/en-us/library/3278tedw.aspx
Reverting to a precivious version is as simple as popping the object off the
stack.
Chuck
Cecco (ITA) said:
Because I need to compare two forms with "equals" method.
My intent is to determine, every time, if a user modified the form,
althoug
if he decided to change a data value and then undo the operation.
If I stored data in a struct when the users undo the operation the
begining
struct and the newone will be equals.
So, I think, but i'm not sure, if I can have a deep copy of a form at the
begining with "equals" method I can know if someone has modified in some
case
the form, also if the datas remain the same.
Phill W. said:
Cecco (ITA) wrote:
I need to know if there's a way to serialize a windows form.
(1) Why?
Forms contain lots and /lots/ of data that you probably won't care about
when serializing it.
I included the [serializable()]/<serializable> in the "myclassform"
declaration, but I
declaration, but Ireceived an error because the windows.form class
isn't marked
as serializable.
And there's probably a Good Reason for that (see (1)).
What are you trying to /achieve/?
If you want to save the Form's data then create a class to hold the data
and teach that class how to save (and reload) itself.
Regards,
Phill W.