Using databinding to display settings

  • Thread starter Thread starter nagar
  • Start date Start date
N

nagar

I was thinking about using databinding to display the user settings.
I'm not using the .NET 2.0 ApplicationSettings but I'm using a class
that contains all the settings.

I have a few questions:

1. What's the best practice to store settings? I like using my own
class as I can choose how to serialize and store the data
2. How do I validate the inserted data? Should the validation logic be
handled by the UI or the underlying business logic
3. I don't think I can revert the changes using a business object, so
my idea is to create a copy of the original settings object and
overwrite it if the user confirms the operation.

Thanks a lot.
Andrea
 
1. What's the best practice to store settings? I like using my own
class as I can choose how to serialize and store the data

If the purpose is similar to ApplicationSettings, I'd use
ApplicationSettings - simply as a time saver.
2. How do I validate the inserted data? Should the validation logic be
handled by the UI or the underlying business logic

An interesting one; obviously if you use ApplicationSettings you can't
do the latter, so it would have to be the former - but the latter is
generally preferable. If you *did* have your own class, then this
could be by exceptions from the property setters (which your UI must
handle) - or it could be via IDataErrorInfo (which some bindings [esp.
grids] will display automatically).
3. I don't think I can revert the changes using a business object, so
my idea is to create a copy of the original settings object and
overwrite it if the user confirms the operation.
Actually, some overly complex things are possible using
TransactionScopes ;-p But don't go there!
Yes - when using databinding, the object is generally updated quite
early, making it a pain to press Cancel. One option is to set the
Binding's DataSourceUpdateMode to Never and do it manually (when OK is
clicked) by using WriteValue().
Alternatively, look into the memento pattern, or take a snapshot using
either ICloneable or serialization; note the ICloneable is less
reliable as it is ambiguous over deep/shallow clone (serialization
will either be deep or will fail).

Marc
 
Hello Andrea,

Would you mind letting me know the result of the suggestions from Marc ? If
you need further assistance, feel free to let me know. I will be more than
happy to be of assistance.

Have a great day!

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks for the suggestions. I'm using a cloned object to store
settings temporarily and copy that upon the user pressing OK.
 
Back
Top