Click here to Skip to main content
15,889,216 members
Home / Discussions / C#
   

C#

 
GeneralRe: ArrayList stored in Application Settings [modified] Pin
DaDennis1220-Mar-09 11:57
DaDennis1220-Mar-09 11:57 
GeneralRe: ArrayList stored in Application Settings Pin
DaveyM6920-Mar-09 12:33
professionalDaveyM6920-Mar-09 12:33 
GeneralRe: ArrayList stored in Application Settings Pin
DaDennis1220-Mar-09 12:38
DaDennis1220-Mar-09 12:38 
GeneralRe: ArrayList stored in Application Settings Pin
DaveyM6920-Mar-09 12:51
professionalDaveyM6920-Mar-09 12:51 
AnswerRe: ArrayList stored in Application Settings Pin
DaDennis1220-Mar-09 12:56
DaDennis1220-Mar-09 12:56 
GeneralRe: ArrayList stored in Application Settings Pin
DaveyM6920-Mar-09 13:10
professionalDaveyM6920-Mar-09 13:10 
GeneralRe: ArrayList stored in Application Settings [modified] Pin
DaveyM6920-Mar-09 14:49
professionalDaveyM6920-Mar-09 14:49 
GeneralRe: ArrayList stored in Application Settings Pin
DaveyM6920-Mar-09 15:53
professionalDaveyM6920-Mar-09 15:53 
Ok this has been bugging me all night. The trick is to use ApplicationSettingsBase[^].
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        private GroupSettings groupSettings = new GroupSettings();
        public Form1()
        {
            InitializeComponent();
            List<Group> groups = groupSettings.Groups;
            if (groups.Count == 0)
            {
                Group group1 = new Group("Test1", true);
                Group group2 = new Group("Test2", false);
                groups = new List<Group>();
                groups.AddRange(new Group[] { group1, group2 });
                groupSettings.Groups = groups;
                groupSettings.Save();
            }
            else
            {
                foreach (Group group in groups)
                {
                    Console.WriteLine(
                    String.Format(
                    "Name={0}, IsVisible={1}",
                    group.Name, group.IsVisible));
                }
            }
        }
    }
    [Serializable]
    public class Group
    {
        public Group()
        {
            Name = string.Empty;
            IsVisible = false;
        }
        public Group(string name)
        {
            Name = name;
            IsVisible = false;
        }

        public Group(string name, bool isVisible)
        {
            Name = name;
            IsVisible = isVisible;
        }
        public string Name { get; set; }
        public bool IsVisible { get; set; }
    }
    internal sealed class GroupSettings : ApplicationSettingsBase
    {
        [UserScopedSetting()]
        [SettingsSerializeAs(System.Configuration.SettingsSerializeAs.Binary)]
        [DefaultSettingValue("")]
        public List<Group> Groups
        {
            get { return (List<Group> )this["Groups"]; }
            set { this["Groups"] = value; }
        }
    }
}


Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

GeneralRe: ArrayList stored in Application Settings Pin
DaveyM6921-Mar-09 9:35
professionalDaveyM6921-Mar-09 9:35 
GeneralRe: ArrayList stored in Application Settings Pin
DaDennis1222-Mar-09 3:47
DaDennis1222-Mar-09 3:47 
GeneralRe: ArrayList stored in Application Settings Pin
DaveyM6922-Mar-09 4:34
professionalDaveyM6922-Mar-09 4:34 
QuestionDézipe file with c# Pin
abbd20-Mar-09 11:09
abbd20-Mar-09 11:09 
AnswerRe: Dézipe file with c# Pin
Mbah Dhaim20-Mar-09 11:15
Mbah Dhaim20-Mar-09 11:15 
GeneralRe: Dézipe file with c# Pin
abbd21-Mar-09 0:08
abbd21-Mar-09 0:08 
AnswerRe: Dézipe file with c# Pin
Ravadre20-Mar-09 12:01
Ravadre20-Mar-09 12:01 
QuestionShow a console window for 10sec in C# console application Pin
abbd20-Mar-09 11:00
abbd20-Mar-09 11:00 
AnswerRe: Show a console window for 10sec in C# console application Pin
Mbah Dhaim20-Mar-09 11:14
Mbah Dhaim20-Mar-09 11:14 
GeneralRe: Show a console window for 10sec in C# console application Pin
abbd20-Mar-09 11:49
abbd20-Mar-09 11:49 
GeneralRe: Show a console window for 10sec in C# console application Pin
Mbah Dhaim20-Mar-09 12:55
Mbah Dhaim20-Mar-09 12:55 
AnswerRe: Show a console window for 10sec in C# console application Pin
Ravadre20-Mar-09 16:40
Ravadre20-Mar-09 16:40 
QuestionVerify if a processes exist Pin
abbd20-Mar-09 9:59
abbd20-Mar-09 9:59 
QuestionHow do I cast a LPARAM? Pin
bbranded20-Mar-09 8:41
bbranded20-Mar-09 8:41 
QuestionRe: How do I cast a LPARAM? Pin
led mike20-Mar-09 8:53
led mike20-Mar-09 8:53 
AnswerRe: How do I cast a LPARAM? [modified] Pin
bbranded20-Mar-09 8:56
bbranded20-Mar-09 8:56 
GeneralRe: How do I cast a LPARAM? Pin
Dan Neely20-Mar-09 9:24
Dan Neely20-Mar-09 9:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.