Reputation: 29155
I'm trying to do something that I thought would be relatively simple in WinForms, but it's not turning out that way.
Here's what I want to do:
Have a ComboBox's dropdown values populated from an array. For example:
Dim versions As String() = New String() {"3", "4"}
cmbVersion.DataSource = versions
Simple, no problem. But where I'm having issues is that I have this same combobox bound to user.settings (a string value) called MyVersion
. The value is currently "4".
When I load my form, I expect the dropdown list will be '3' and '4' and the displayed text will be whatever is in MyVersion
. This doesn't work. The value is always "3" and changing it to "4" in the combobox has no affect on MyVersion
.
What am I doing wrong here?
Upvotes: 2
Views: 447
Reputation: 14387
First of all, I think you should realize that the value that comes from My.Settings.MyVersion is not what you define in your Project Properties/Settings. Those are just the intial (default) values. The actual value comes from the user.config file. The user.config file is created automatically at run time the first time the application is run by a new user and a non-default value is written to a user-scoped setting. The location is something like:
c:\Documents and Settings\[username]\Local Settings\Application Data\[companyname][appdomainname][eid][hash]\[verison]
Although this may differ per OS.
Secondly, the setting does not get persisted until you tell it to, by calling:
My.Settings.Save()
I hope this clarifies things a bit.
You can bind the value by setting the SelectedItem property, either in the designer or by calling:
cmbVersion.SelectedItem = My.Settings.Myversion
Upvotes: 1