Results 1 to 7 of 7

Thread: [RESOLVED] How to Save Combobox Items in MySettings?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    69

    Resolved [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:

    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.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,414

    Re: How to Save Combobox Items in MySettings?

    try this:

    vb Code:
    1. Dim strings(ComboBox1.Items.Count - 1) As String
    2. ComboBox1.Items.CopyTo(strings, 0)
    3. My.Settings.SettingName.Clear()
    4. My.Settings.SettingName.AddRange(strings)

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,414

    Re: How to Save Combobox Items in MySettings?

    to reload:

    vb Code:
    1. Dim strings(My.Settings.SettingName.Count - 1) As String
    2. My.Settings.SettingName.CopyTo(strings, 0)
    3. ComboBox1.Items.AddRange(strings)
    Last edited by .paul.; Jun 15th, 2009 at 06:48 AM.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    69

    Re: How to Save Combobox Items in MySettings?

    Thankyou so much .paul.! All problems now fixed (hopefully). :P Thanks so much for your help.
    Last edited by PR0 6AM3R; Jun 15th, 2009 at 06:56 AM.

  5. #5
    Lively Member
    Join Date
    May 2009
    Posts
    66

    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

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,414

    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

  7. #7
    Lively Member
    Join Date
    May 2009
    Posts
    66

    Re: [RESOLVED] How to Save Combobox Items in MySettings?

    Ok thanks Paul. It works too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width