Search code examples
.netwinformssettingsapplication-settings

Resetting a key in My.Setting


I know it's possible to reset the My.Settings with Reset() method.

Is there anyway to do the same thing for just one setting? Or simple getting its default value instead of the one changed by user. (I'm referring to User Scope Settings)


Solution

  • You cannot reset one setting. It is easy to get the default value through the Properties collection. Specifically, the SettingsProperty's DefaultValue property. Moreover, the PropertyValues collection contains SettingsPropertyValue objects that allow you to determine if a property/setting has changed through the IsDirty or UsingDefaultValue properties.

        Dim a As Object = My.Settings.Properties.Item("fred").DefaultValue
        Dim b As Boolean = My.Settings.PropertyValues.Item("fred").IsDirty
        Dim c As Boolean = My.Settings.PropertyValues.Item("fred").UsingDefaultValue
    

    I wish there was a way to get these values without having to specify the name of the setting.