I am trying to use the built in .NET application settings. So for instance I have a User setting of year.
If the end user changes the setting in the program I need to respond by refreshing the data displayed.
I currently have code like below to do this:
Settings.Default.PropertyChanged += SettingsChanged;
//on year change clear out the grid and update the data
private void SettingsChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "year")
{
grdStudentCourseSearch.DataSource = null;
grdStudentCourseSearch.DataMember = null;
UpdateData();
}
}
As you can see their seems to only be an event handler for all the settings and I am having to use e.PropertyName to compare a string to see which property has changed. Is there a better way to do this? Potentially if I change property names later this could be forgotten.