Hi,
I wrote a blog entry about how to do this
http://dsmyth.blogspot.com/2006/05/saving-user-interface-state.html
Generally what you want to do is create a class that contains all the data entered/displayed on the form. Add two properties to the form, one property that gets the forms data and returns an instance of the class, the other property takes an instance of the class and uses it to populate the controls on the form.
If you do this you can hold the data in the form (the forms state) seperately from the form. So when the form closes the class can still be held in memory, or saved and read to a file, or even used by another form.
You can write methods inside the state class that saves (persist) the data to any data store, file, excel, access. If you write the method in the class then every instance of the class knows how to persist itself. i.e. MyFormState.SaveToAccess() or MyFormState.SaveToFile(), or even through the form as in MyForm.State.SaveToFile() - state here is the forms property that gets an instance of the state class, the forms data in one class.
This works very well I've used it in a number of applications.
|