Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 681011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:26:10+00:00 2026-05-14T01:26:10+00:00

After much research and trial and error I found how to store the items

  • 0

After much research and trial and error I found how to store the items for a ListBox and ComboBox in the app.Config. I am heavily indebted to Jon Rista, who wrote a series of articles about the Net 2.0 Configuration classes. I constructed a (large!) code snippet that will generate all the code you need by just inserting three strings!


Enjoy!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:26:10+00:00Added an answer on May 14, 2026 at 1:26 am
    <?xml version="1.0" encoding="utf-8"?>
    <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
      <CodeSnippet Format="1.0.0">
        <Header>
          <Title>ConfigurationElementCollectionBasicMap</Title>
          <Author>Andre Steffens, heavily indebted to Jon Rista</Author>
          <Description>Derive from ConfigurationElementCollection of type BasicMap: Collection and Section</Description>
          <HelpUrl></HelpUrl>
          <SnippetTypes />
          <Keywords />
          <Shortcut>cecb</Shortcut>
        </Header>
        <Snippet>
          <References />
          <Imports />
          <Declarations>
            <Literal Editable="true">
              <ID>tag</ID>
              <Type></Type>
              <ToolTip></ToolTip>
              <Default>tag</Default>
              <Function></Function>
            </Literal>
            <Literal Editable="true">
              <ID>NameSpace</ID>
              <Type></Type>
              <ToolTip></ToolTip>
              <Default>NameSpace</Default>
              <Function></Function>
            </Literal>
            <Literal Editable="true">
              <ID>Type</ID>
              <Type></Type>
              <ToolTip></ToolTip>
              <Default>My</Default>
              <Function></Function>
            </Literal>
          </Declarations>
          <Code Language="csharp" Kind="type decl" Delimiter="$"><![CDATA[using System.Configuration;
    
    namespace $NameSpace$.Configuration
    {
        public class $Type$ElementCollection: ConfigurationElementCollection
        {
            #region Constructor
            public $Type$ElementCollection()
            {
            }
            #endregion
    
            #region Properties
            public override ConfigurationElementCollectionType CollectionType
            {
                get { return ConfigurationElementCollectionType.BasicMap; }
            }
            protected override string ElementName
            {
                get { return "$tag$"; }
            }
    
            protected override ConfigurationPropertyCollection Properties
            {
                get { return new ConfigurationPropertyCollection(); }
            }
            #endregion
    
            #region Indexers
            public $Type$Element this[int index]
            {
                get{ return ($Type$Element)BaseGet(index);}
    
                set
                {
                    if (BaseGet(index) != null) BaseRemoveAt(index);
                    base.BaseAdd(index, value);
                }
            }
    
            public new $Type$Element this[string key]
            {
                get { return ($Type$Element) BaseGet(key); }
            }
            #endregion
    
            #region Methods
            public void Add($Type$Element item)
            {
                base.BaseAdd(item);
            }
    
            public void Remove($Type$Element item)
            {
                BaseRemove(item);
            }
    
            public void RemoveAt(int index)
            {
                BaseRemoveAt(index);
            }
            #endregion
    
            #region Overrides
            protected override ConfigurationElement CreateNewElement()
            {
                return new $Type$Element();
            }
    
            protected override object GetElementKey(ConfigurationElement element)
            {
                var configurationElement = element as $Type$Element;
                return configurationElement == null
                           ? null
                           : configurationElement.Key;
            }
            #endregion
        }
    
        public class $Type$sSection: ConfigurationSection
        {
            #region Constructors
            static $Type$sSection()
            {
                s_name = new ConfigurationProperty(
                    "name",
                    typeof(string),
                    null,
                    ConfigurationPropertyOptions.IsRequired
                    );
    
                s_$tag$s = new ConfigurationProperty(
                    "",
                    typeof($Type$ElementCollection),
                    null,
                    ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsDefaultCollection
                    );
    
                s_properties = new ConfigurationPropertyCollection {s_name, s_$tag$s};
            }
            #endregion
    
            #region Fields
            private static readonly ConfigurationPropertyCollection s_properties;
            private static readonly ConfigurationProperty s_name;
            private static readonly ConfigurationProperty s_$tag$s;
            #endregion
    
            #region Properties
            public string Name
            {
                get { return (string)base[s_name]; }
                set { base[s_name] = value; }
            }
    
            public $Type$ElementCollection $Type$s
            {
                get { return ($Type$ElementCollection)base[s_$tag$s]; }
            }
    
            protected override ConfigurationPropertyCollection Properties
            {
                get { return s_properties; }
            }
            #endregion
        }
    
        public class $Type$Element: ConfigurationElement
        {
            #region Constructors
            static $Type$Element()
            {
                s_key = new ConfigurationProperty(
                    "key",
                    typeof(string),
                    null,
                    ConfigurationPropertyOptions.IsRequired
                    );
    
                s_value = new ConfigurationProperty(
                    "value",
                    typeof(string),
                    null,
                    ConfigurationPropertyOptions.None
                    );
    
                //initialize further fields here
    
                s_properties = new ConfigurationPropertyCollection {s_key, s_value};
            }
            #endregion
    
            #region Fields
            private static readonly ConfigurationPropertyCollection s_properties;
            private static readonly ConfigurationProperty s_key;
            private static readonly ConfigurationProperty s_value;
            //add fields at your liberty!
    
            #endregion
    
            #region Properties
            public string Key
            {
                get { return (string)base[s_key]; }
                set { base[s_key] = value; }
            }
    
            public string Value
            {
                get { return (string)base[s_value]; }
                set { base[s_value] = value; }
            }
    
            //implement further properties here
    
            protected override ConfigurationPropertyCollection Properties
            {
                get { return s_properties; }
            }
        }
            #endregion
    }
    
    //example app.config snippet
    /*
    <configuration>
      <configSections>
        <section name="$tag$Listing" type="$NameSpace$.Configuration.$Type$sSection, $NameSpace$" />
      </configSections>
    
      <$tag$Listing name="$tag$s">
        <$tag$ key="key1" value="value1" />
        <$tag$ key="key2" value="value2" />
      </$tag$Listing>
    </configuration>
    */]]></Code>
        </Snippet>
      </CodeSnippet>
    </CodeSnippets>
    

    Typical usage would be:

    //WPF
    public Window1()
        {
            InitializeComponent();
            var section = ConfigurationManager.GetSection("$tag$Listing") as $Type$sSection;
            MyComboBox.ItemsSource = section.$Type$s;
            MyComboBox.DisplayMemberPath="Value";
        }
    
    //WinForms
    public Window1()
        {
            var section = ConfigurationManager.GetSection("$tag$Listing") as $Type$sSection;
            MyComboBox.Items = section.$Type$s;
            MyComboBox.DisplayMember="Value";
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dilemma on my hands. After much trial and error, I still
After much research, I have found that Laravel is very nice. I have a
Not knowing the proper way, after much research on the web I found so
OK, after much research, and help with stackoverflow users, I've narrowed down how to
So I've decided after much debate and research to use symfony on my next
After much research I am still stumped. I have a serial port object which
After much research about the best way to save an image to a sqlite
I installed PHP and MySql separately, configured IIS and php.ini, after much research I
After much research I am a little confused by which identity tracker I should
After much research, I have learned that binding the scroll event to the $(window)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.