I'm saving the grid layouts via the XML system to the Application settings folder. I load them up just before the view is opened, which means we have our DataSources, and save them out when the user exits the app. Works great!
But I'd like a "reset to factory" feature so if they don't like what they've done they can easily return everything to an original state. I thought the easy solution to returning the grids to their original settings would be to simply delete the files out of the settings folder.
The problem is that the grids have already loaded up their settings by that point. So when they exit the app, the system saves out those settings again.
Is there a better way to do this?
I delete the file as you suggest, set the grid datasource to nothing then reset the datasource. At least in my version there is no restore default settings. It would be easy to do if you wanted. Just save a file with the default settings then if the user wants to restore defaults just load that file. I use a context menu to accomplish that.
Hope this helps
So.. there's a Reset method on the grid's DisplayLayout that will return the grid to the default settings. But this probably isn't what you want.
You have probably made changes to the grid in your code and at design-time. And even if you didn't explicitly do this, the grid loads a Preset when you place one on a form in the designer.
What you probably need to do is save the original layout of the grid before you load the layout from a file. You don't even have to save it to a file, you can save it to a MemoryStream. Then just keep the stream around and if the user decides to reset, Load the layout from the stream.
Yeah, works OK as long as you do it late enough in the load process.
What I did was look to see if the settings folder existed, and/or if the "factory settings" file was inside it. If it wasn't, I saved out the layout immediately before anything changed. Then when the user selects Reset, it looks for those files and loads them in. The user's own settings are saved to a separate set of similarly named files.
The only problem is that I had the load method in my main view's instantiation, which was too early. If you saved at that point the custom layout from designer hadn't been loaded yet and you got a different set of defaults. Moving it to the OnLoad fixed that.
Well the idea of this method is to reset to factory, not "what it was earlier this session". That implies the only real solution is to save out the original layout. Let's see what happens...