开发者

Question about saving user settings!

I want to allow users to m开发者_如何转开发ove column headers to the order that they want them and then save those settings so that they will be the same each time the user logs in to the application. I have a datagrid that does not have static headers. Its pulls its headers in from xml files. Since i do not have static headers, how would i save user settings in the data grid? Thanks


http://msdn.microsoft.com/en-us/library/aa730869%28v=vs.80%29.aspx

There is a type of file, similar to but different that a config file, called the settings file. In it, you can define settings on an application-wide, or per-user basis. Think of it as if the AppSettings section of your config file got its own file, and you keyed the appSettings not only to name, but to user (or "Application"). I think this is what you're looking for.

Keep in mind that loading a lot of setting regarding the layout of a DataGridView will impact performance; you have to load the settings file from the file system, read all the keyed settings values, and adjust the column order.

EDIT: Responding to the comment, yes it will work with dynamic column names, provided you design your use of the settings properly. How you would go about doing that depends on how the columns can vary. If it's a localization thing, and columns sourced exactly the same way can have different names for translation or departmental jargon purposes, then define a constant internal name for that column source and use that in the settings. If users can choose a subset of a known collection of columns, then try defining a single setting that is a comma-separated list of column names, in the proper order. When retrieving it, match each column name in the list to the headers in the DGV, being intelligent about columns that don't appear in one or the other. You could make the scenario of missing/extra column names unlikely by using the setting to set up the columns in the first place, and saving the names when you close the window or exit the app. That way, what the user sees on the first load of a new app is ordered the same as it was when they shut it down last time. Again, I would avoid using the actual column header text, and instead using some immutable ID for the column, because if the column header text ever has to change, the settings will become invalid, and best-case all the users will have to re-order their columns; worst-case, the app will break completely if you weren't flexible about nonexistent column names.

One caveat: Because settings files are local to the installation of the application, if the user uses multiple instances of the app (say one on a desktop and another on a laptop) and expects to see the same layout regardless of from where they log in, the settings file is not a good solution. You would be better served in this case by storing the user preferences in a central repository like a database, and retrieving it on login.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜