I'm attempting to utilize the .NET 2.0 ApplicationSettings feature for the first time, and find it a bit... puzzling in some ways. I'm hoping someone can help me figure out where i'm going wrong.
I have a generic settings class which i've implemented that is a subclass of ApplicationSettingsBase. I've implemented a property, and tagged it. This seems to work
I've then tried to bind a listbox control to the property, and this also seems to work. When I open the form, it loads the properties just fine.
The problem i'm running into is that if I want to update the settings and databinding without reloading the form, it doesn't seem to work. There are no methods to refresh the binding, and from what i'm reading, it should just auto-update (ApplicationSettingsBase implements IPropertyChangeNotify, which DataBindings should subscribe to.. but it doesn't seem to be working). You also can't manually update the listbox if you have a DataBinding.
So here's my code:
Settings.cs
public class Settings : ApplicationSettingsBase
{
public Settings()
{
if (FixedBooks == null) FixedBooks = new List<string>();
}
[UserScopedSetting()]
public List<string> FixedBooks
{
get { return (List<string>)this["FixedBooks"]; }
protected set { this["FixedBooks"] = value; }
}
}
SettingsForm.cs
Settings _settings = new Settings();
private void SettingsForm_Load(object sender, EventArgs e)
{
lbFixedColumns.DataBindings.Add(new Binding("DataSource", _settings,
"FixedBooks", false, DataSourceUpdateMode.OnPropertyChanged));
}
private void DoSomething()
{
_settings.FixedBooks.Add("Test");
}
My understanding is that adding something to the ApplicationSettings should fire the IPropertyChangedNotify to alert the control binding that the property has changed, and force it to reload.. but this doesn't seem to be happening.
What am I missing?
EDIT:
I believe I know what the problem is. The problem is that i'm altering the contentes of the collection in the Settings class, but not changing the actual property itself (which is the collection itself). I think i would have to actually add or remove the entire collection to get the IPropertyChangedNotify to fire, which isn't happening.
I'm not sure what the solution to this problem is.