Hello,
I would like to commit the data put in a checkedlistbox to the user.config. I have found a way to commit them to my.settings but no matter what Save() method I call, it does not commit the new data (that is not bound to a control, through the propertybindings) to the user.config, either immediately or when I shutdown the application. Which means, when I loop through the settings when the application starts back up, the data is not there to be added back to the checkedlistbox. I have put save methods in the formclosing events as well as when the data is created in the my.settings. using my.mysettings, my.settings and my.settings.default. Thank you in advance for your input.
This first method is a called when a button is pushed. it checks the text and then calls the next method (AddProperty) which should add the property to my.settings and save it to user.config, but my understanding is that it is not written to the file till the applicatoin closes.
This method is the one that should add the property to my.settings (you can see by my commented out lines i tried it a couple different ways):
Thank you.
I would like to commit the data put in a checkedlistbox to the user.config. I have found a way to commit them to my.settings but no matter what Save() method I call, it does not commit the new data (that is not bound to a control, through the propertybindings) to the user.config, either immediately or when I shutdown the application. Which means, when I loop through the settings when the application starts back up, the data is not there to be added back to the checkedlistbox. I have put save methods in the formclosing events as well as when the data is created in the my.settings. using my.mysettings, my.settings and my.settings.default. Thank you in advance for your input.
This first method is a called when a button is pushed. it checks the text and then calls the next method (AddProperty) which should add the property to my.settings and save it to user.config, but my understanding is that it is not written to the file till the applicatoin closes.
VB.NET:
Private Sub btnErrorMessageAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnErrorMessageAdd.Click
If txtAddError.Text <> "" And IsNothing(txtAddError.Text) = False Then
chklstErrorMessages.Items.Add(txtAddError.Text, True)
End If
AddProperty(txtErrorName.Text, txtAddError.Text, GetType(String))
'My.MySettings.Default.Reload()
btnErrorMessageAdd.Visible = False
txtAddError.Visible = False
btnCancelAdd.Visible = False
lblErrorName.Visible = False
lblErrorMessage.Visible = False
txtErrorName.Visible = False
txtErrorName.Clear()
txtAddError.Clear()
End Sub
VB.NET:
Private Sub AddProperty(ByVal propertyName As String, _
ByVal defaultValue As String, ByVal propertyType As Type)
'Dim providerName As String = "LocalFileSettingsProvider"
'Dim attributes As New Configuration.SettingsAttributeDictionary()
'Dim attr As New Configuration.UserScopedSettingAttribute()
'attributes.Add(attr.TypeId(), attr)
'Dim prop As New Configuration.SettingsProperty( _
' New Configuration.SettingsProperty(propertyName, propertyType, _
'My.MySettings.Default.Providers(providerName), False, defaultValue, _
'Configuration.SettingsSerializeAs.String, attributes, False, False))
'My.MySettings.Default.Properties.Add(prop)
'My.Settings.Save()
Dim p As Configuration.SettingsProperty
p = New Configuration.SettingsProperty(propertyName)
p.Provider = My.Settings.Providers("LocalFileSettingsProvider")
p.DefaultValue = defaultValue
p.SerializeAs = Configuration.SettingsSerializeAs.String
p.Attributes.Add(GetType(Configuration.UserScopedSettingAttribute), _
New Configuration.UserScopedSettingAttribute())
p.PropertyType = GetType(String)
My.Settings.Properties.Add(p)
'Settings.Properties.Add(p)
'My.Settings.PropertyValues.Add(New Configuration.SettingsPropertyValue(p))
'My.Settings.Item(p.Name) = defaultValue
My.Settings.Save()
End Sub