Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C# Storing Application Settings

  • 14-07-2010 02:56PM
    #1
    Registered Users, Registered Users 2 Posts: 1,841 ✭✭✭


    I'm attempting to store application settings, however I'm having trouble storing/accessing multiple values.

    E.g I want to store a text list of colours for use in a drop-down box, I've edited my app.config to this;
    <setting name="Colours" serializeAs="String">
    <value>Green</value>
    <value>White</value>
    <value>Gold</value>
    </setting>
    

    But
    Properties.Settings1.Default.Colours
    
    will only contain the 1st value - "Green".

    Any ideas? Or is there an easier way to store application settings with multiple values?


Comments

  • Registered Users, Registered Users 2, Paid Member Posts: 2,032 ✭✭✭lynchie


    Been a while since I done some .net stuff, but I think you need to serialize your settings as xml and use xml as your value or something along those lines as serializeAs="String" just stores a single value
    <setting name="Colours" serializeAs="XML">
    <value>
    <colorlist>
    <color>Green</color>
    <color>White</color>
    </colorlist>
    </value>
    </setting>
    


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    The problem seems to be that that you have 3 value elements in your setting and you should only have one as you're using serializeAs="string". Have a read of this: http://msdn.microsoft.com/en-us/library/ms229207.aspx which explains the elements. Then you could have a read of: http://msdn.microsoft.com/en-us/library/k4s6c3a0.aspx and perhaps roll your own custom settings.

    You may even be able to serialize it as XML and then deserialize the XML as you want it in code.

    <edit>
    lynchie beat me to it
    </edit>


  • Registered Users, Registered Users 2 Posts: 1,841 ✭✭✭CountingCrows


    Muchas gracias!

    I'll test it out in the morning.


Advertisement