Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Application Settings. How to iterate ?

Application Settings. How to iterate ?

Scheduled Pinned Locked Moved C#
csharpvisual-studiotutorialquestionworkspace
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    davebarkshire
    wrote on last edited by
    #1

    Visual Studio 2008 / C# / windows application I have some application settings and would like to iterate through them so that I can put them into a list. So far I have not been able to find a way. I've tried to use an enumerator

    IEnumerator enuEnumerator = Properties.Settings.Default.Properties.GetEnumerator();
    while (enuEnumerator.MoveNext())
    {
    MessageBox.Show(enuEnumerator.Current.ToString());
    }

    but the string is "System.Configuration.SettingsProperty" Also, I cannot use an indexer because a string is required raher than a number...

    Properties.Settings.Default.Properties[i]

    Does anyone know how to do this? :confused:

    A L D 3 Replies Last reply
    0
    • D davebarkshire

      Visual Studio 2008 / C# / windows application I have some application settings and would like to iterate through them so that I can put them into a list. So far I have not been able to find a way. I've tried to use an enumerator

      IEnumerator enuEnumerator = Properties.Settings.Default.Properties.GetEnumerator();
      while (enuEnumerator.MoveNext())
      {
      MessageBox.Show(enuEnumerator.Current.ToString());
      }

      but the string is "System.Configuration.SettingsProperty" Also, I cannot use an indexer because a string is required raher than a number...

      Properties.Settings.Default.Properties[i]

      Does anyone know how to do this? :confused:

      A Offline
      A Offline
      Alan N
      wrote on last edited by
      #2

      Hi, If you cast the enumerator's Current value to a SettingsProperty then you should get to the information you need. My code essentially does that and shows how to enumerate both the default and current value collections.

      internal void ShowSettings() {
        Console.WriteLine("Default values");
        SettingsPropertyCollection spc = Properties.Settings.Default.Properties;
        foreach (SettingsProperty sp in spc) {
          Console.WriteLine("{0} '{1}'", sp.Name, sp.DefaultValue);
        }
      
        Console.WriteLine("\\nCurrent values");
        SettingsPropertyValueCollection spvc = Properties.Settings.Default.PropertyValues;
        foreach (SettingsPropertyValue spv in spvc) {
          Console.WriteLine("{0} '{1}'", spv.Name, spv.PropertyValue);
        }
      }
      

      Alan.

      1 Reply Last reply
      0
      • D davebarkshire

        Visual Studio 2008 / C# / windows application I have some application settings and would like to iterate through them so that I can put them into a list. So far I have not been able to find a way. I've tried to use an enumerator

        IEnumerator enuEnumerator = Properties.Settings.Default.Properties.GetEnumerator();
        while (enuEnumerator.MoveNext())
        {
        MessageBox.Show(enuEnumerator.Current.ToString());
        }

        but the string is "System.Configuration.SettingsProperty" Also, I cannot use an indexer because a string is required raher than a number...

        Properties.Settings.Default.Properties[i]

        Does anyone know how to do this? :confused:

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You can iterate by just accessing the settings property in a foreach loop

                foreach (System.Configuration.SettingsProperty prop in Properties.Settings.Default.Properties)
                {
                    //prop.DefaultValue.ToString();
                }
        
        1 Reply Last reply
        0
        • D davebarkshire

          Visual Studio 2008 / C# / windows application I have some application settings and would like to iterate through them so that I can put them into a list. So far I have not been able to find a way. I've tried to use an enumerator

          IEnumerator enuEnumerator = Properties.Settings.Default.Properties.GetEnumerator();
          while (enuEnumerator.MoveNext())
          {
          MessageBox.Show(enuEnumerator.Current.ToString());
          }

          but the string is "System.Configuration.SettingsProperty" Also, I cannot use an indexer because a string is required raher than a number...

          Properties.Settings.Default.Properties[i]

          Does anyone know how to do this? :confused:

          D Offline
          D Offline
          davebarkshire
          wrote on last edited by
          #4

          Thanks both for your prompt responses. Case closed.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups