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.