Welcome to MSDN Blogs Sign in | Join | Help

Client Settings - Part 3

RichB has some interesting questions in his comments about my earlier post on the client settings feature. I thought it might be worth a separate post to answer them.

I don't have the CTP available, but from the documentation it appears that ApplicationSettingsBase can read and write to a collection of providers. I can understand the writing to multiple providers (saving the same values into multiple locations) but how does it read the same values from multiple locations.

Yes, a settings class can talk to multiple providers, but each setting (or property) in it is associated with a single provider. This just means that you can have different providers for different settings in a settings class.

I also hope you have a good "story" for plug-in based applications. For example, Lutz Roeder's Reflector and Nikhil's Web Matrix are both heavily pluggable. Is there a prescribed way for each plug-in/component to obtain and save configuration information to the same store?

Yes, we have a story for this scenario. There is an interface called IPersistComponentSettings that any component can implement to save its own settings when hosted in an application. For example, the ToolStrip control implements this. Someone using the ToolStrip in their app can just set a property called SaveSettings to true and the ToolStrip will save/restore settings automatically without the user having to set anything up.

I'm also a bit hazy on Setting Groups. I've noticed the SettingsGroupNameAttribute - but am not entirely clear on how it's meant to be used.

Usually, the settings class name is used to identify your settings in the store. If you want them stored with a different name or share settings with some other class, you can use the SettingsGroupNameAttribute to rename/redirect your settings.

Finally, do you have generic methods for loading from the store to prevent boxing?

No, but that's a good suggestion. We will consider doing this.

Published Friday, June 18, 2004 10:00 AM by rprabhu

Comments

# Settings API Quandary

Wednesday, January 12, 2005 3:57 PM by Objects, Systems and Everywhere In-Between

# Enregistrer un parametre avec My.Settings

Saturday, March 26, 2005 8:31 PM by Cyril's Blog

# Enregistrer un parametre avec My.Settings

Sunday, March 27, 2005 4:48 AM by Cyril's Blog

# re: Client Settings - Part 3

Friday, July 29, 2005 4:56 AM by MDeevi
Hi Prabhu,

I had seen your client settings blog from part1 to part3, in all of these you are explaining about the ApplicationSettingsBase but I want to write my own custom SettingsProvider class. please help me out in
How to write a custom SettingsProvider class?I am asking this question as we could not able to get any links explaining it in better way. If you can provide any samples that will be helpful and also please provide us a solution how to set this custom SettingsProvider to the application, so that application reads the settings from the custom SettingsProvider rather than default LocalFileSettingsProvider

Thanks
MDeevi.

# re: Client Settings - Part 3

Friday, July 29, 2005 1:17 PM by rprabhu
I have replied to your question here: http://blogs.msdn.com/rprabhu/archive/2005/06/29/434007.aspx

# re: Client Settings - Part 3

Tuesday, August 30, 2005 5:16 PM by Bas
I tried to set the SaveSettings property on a MenuBar (VS2005 B2) but it doesn't exist, MenuBar doesn't appear to implement IPersistComponentSettings at all, nor can I find any other component that does.
Any suggestions?

# re: Client Settings - Part 3

Wednesday, August 31, 2005 3:33 AM by rprabhu
The *Strip controls now implement auto-save of settings in a different way. Check out the LoadSettings() and SaveSettings() methods on the ToolStripManager class.

# re: Client Settings - Part 3

Friday, February 24, 2006 8:16 AM by Mark Swaffer
I am adding an object that inherits from ToolStrip to my ToolStripContainer class. This works fine, however, when i come to use the ToolStripManager.LoadSettings method I am getting an exception but I cannot figure out why. Have you any ideas? I have included the exception detail:

System.ArgumentNullException occurred
 Message="Value cannot be null.\r\nParameter name: value"
 Source="System.Windows.Forms"
 ParamName="value"
 StackTrace:
      at System.Windows.Forms.ToolStripItemCollection.CheckCanAddOrInsertItem(ToolStripItem value)
      at System.Windows.Forms.ToolStripItemCollection.Insert(Int32 index, ToolStripItem value)
      at System.Windows.Forms.ToolStripSettingsManager.ApplyToolStripSettings(ToolStrip toolStrip, SettingsStub settings, Dictionary`2 itemLocationHash)
      at System.Windows.Forms.ToolStripSettingsManager.ApplySettings(ArrayList toolStripSettingsToApply)
      at System.Windows.Forms.ToolStripSettingsManager.Load()
      at System.Windows.Forms.ToolStripManager.LoadSettings(Form targetForm, String key)
      at SensusTech.PAS.UI.PASUI.LoadSettings() in C:\Development\Cream\PAS\UI\PASUI.cs:line 1583

# re: Client Settings - Part 3

Sunday, February 26, 2006 5:46 AM by rprabhu
Hmm, it appears to be running into a null ToolStripItem. Not sure why. I would recommend contacting Jessica (ToolStrip developer) through her blog at http://blogs.msdn.com/jfoscoding to see if she can help.

Alternately, you could report this issue through MSDN Product Feedback - you can usually expect to get a quick response that way.

# re: Client Settings - Part 3 - arrays

Wednesday, May 31, 2006 10:55 PM by Nayan
Hi Prabhu

I have property which is of type class x and is an array.  It does not serialize and complains that class x is not defined as serializable.  Here's what class x looks like:

namespace xSettings
{
[Serializable]
public class x
{
 private string FName;
 private string FAddress;

 public string Name{ get {return FName;} } set {FName = value;} }
 public string Address{ get {return FAddress;} } set {FAddress = value;} }
}
}

and is defined in xApp application settings as follows:

Name -> MyList
Type -> xSettings.x[]
Scope -> User

And in code, (C#) I save this way:

Settings.Default.MyList = arrList;
Settings.Default.Save();

How can I save arrays?

TIA
Nayan

# re: Client Settings - Part 3

Wednesday, June 07, 2006 3:26 PM by rprabhu
Nayan:
Hmm, this should work, but there are some subtleties around the VS settings designer.

I have moved to a different team in Microsoft a few months back, so I am not in touch with this stuff. I recommend contacting Johan Stenberg through his blog - http://blogs.msdn.com/johan_stenbergs_blog/ - he may be able to help. In fact, he might already have a post which answers your question.
New Comments to this post are disabled
 
Page view tracker