[RESOLVED] How to Save Combobox Items in MySettings?
Well currently I'm needing to store various settings, strings, integers, items, etc, within the program settings. So far this has gone without a snag and is working as planned except for one thing, Comboboxes. I have browsed through the various types of settings I can save to and the closest is a "System.Collection.Specialized.StringCollection", however VB is throwing up an error saying that:
Quote:
Error 1 Value of type 'System.Windows.Forms.ComboBox.ObjectCollection' cannot be converted to 'System.Collections.Specialized.StringCollection'. C:\Users\User\AppData\Local\Temporary Projects\Project\Form1.vb 12 34 Project
So my question is this; How would I go about saving the items in a Combobox?
Thanks. :)
Re: How to Save Combobox Items in MySettings?
try this:
vb Code:
Dim strings(ComboBox1.Items.Count - 1) As String
ComboBox1.Items.CopyTo(strings, 0)
My.Settings.SettingName.Clear()
My.Settings.SettingName.AddRange(strings)
Re: How to Save Combobox Items in MySettings?
to reload:
vb Code:
Dim strings(My.Settings.SettingName.Count - 1) As String
My.Settings.SettingName.CopyTo(strings, 0)
ComboBox1.Items.AddRange(strings)
Re: How to Save Combobox Items in MySettings?
Thankyou so much .paul.! :D All problems now fixed (hopefully). :P Thanks so much for your help. :)
Re: [RESOLVED] How to Save Combobox Items in MySettings?
Sorry paul but tell me
i met error when using your code. may be i have not declared something yet.
Code:
'SettingName' is not a member of 'WindowsApplication9.My.MySettings'. D:\CHƯƠNG TRÌNH CHÍNH\GIAO DIỆN\formappearstyle\WindowsApplication9\WindowsApplication9\Form1.vb
Re: [RESOLVED] How to Save Combobox Items in MySettings?
in your design time IDE goto (menus)
Project-->Properties-->Settings
add a new setting, change the type to specialized.stringcollection, click the box in the value column, then click the ellipsis at the far right of the value box. press enter then click OK. you now have a specialized.stringcollection setting
Re: [RESOLVED] How to Save Combobox Items in MySettings?
Ok thanks Paul. It works too.