Click here to Skip to main content
15,898,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have in my program custom property grid, where all properties are bindable from viewModel. In this property grid there are also 2 buttons - SaveBtn and EditBtn. User edit properties in property grid. When SaveBtn is clicked, all properties must be saved in a database. If user wants to edit properties, he clicks EditBtn and then before saving properties to database(SaveBtn is clicked), should appear new window, where user chooses a reason of modification of a properties. On that window there are also three buttons - ExitWithSavingToDatabase, ExitWithoutSavingToDatabase and Cancel.

If user chooses Cancel, all changes should be canceled. But properties in viewModel already have new values. My question is - how can I reset properties to old values??? I was thinking of reloading properties from database, but if there is a better solution, where I can do it without using database?
Posted

1 solution

Create a backup field that maintains the original loaded values,
Then when cancel is clicked, just reload from there.
If either Save option is click, update the backupfields with the new values.
 
Share this answer
 
Comments
Alexander Dymshyts 19-Jul-13 7:00am    
and if there are hundred properties, so my object should keep copy of hundred properties. Do I understand you right?
Pheonyx 19-Jul-13 7:06am    
Yes you understood my response right... however, I didn't notice something key about your question.
In WPF you can set the UpdateSourceTrigger in the data binding to be 'Explicit'
Then in your save command you can call the "UpdateSource" method which should update your underlying viewmodel.
Then if necessary update the database.

Without calling "updatesource" the changes are not persisted back to the viewmodel.
Alexander Dymshyts 19-Jul-13 7:13am    
I just wanted to know, if I understand you right, because I don't think that keeping a copy of a lot of properties is a good way. But I like your idea with UpdateSource. Thank you for help
Pheonyx 19-Jul-13 7:16am    
No problem, hope it solves the issue :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900