VS 2015 "Sub category" in My.Settings-VBForums
Results 1 to 5 of 5

Thread: "Sub category" in My.Settings

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2009
    Posts
    375

    "Sub category" in My.Settings

    There is a way to create a "sub category" in My.Settings?

    If I write "My.Settings.Reset()" I reset ALL the settings to the original values.

    I would like to reset ONLY some of them, something like: "My.Settings.Names.Reset()".

    That's possible?

    Ty.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,251

    Re: "Sub category" in My.Settings

    Not that I know of... but an alternative method would be to create a Sub which resets the ones you want.

    Depending on how many items you have in each "sub category", the code might be a bit long (unless you can use an array and a loop), but that isn't too important because it's in a sub you can hide after you've written it.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2009
    Posts
    375

    Re: "Sub category" in My.Settings

    Quote Originally Posted by si_the_geek View Post
    Not that I know of... but an alternative method would be to create a Sub which resets the ones you want.....
    And how can I reset the ones I want?

    I can do My.Settings.Reset() but I can't do My.Settings.SettingX.Reset()

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,546

    Re: "Sub category" in My.Settings

    I don't think that there is a way to automatically reset just some settings. What I think you would have to do is open the application configuration file and get the default values for the settings of interest from that, then simply assign those values to those settings.

    If I remember correctly, you can find an example of opening a configuration file in my CodeBank thread on Protected Configuration. The code to access the section you want will be slightly different but you should be able to work out how with a bit of research. There's a link to my CodeBank threads in my signature below.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,188

    Re: "Sub category" in My.Settings

    Could do something like this:

    VB.Net Code:
    1. Public Class Form1
    2.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    3.         My.Settings.NameSetting1 = "Kris"
    4.         'Reset single
    5.         My.Settings.Reset(NameOf(My.Settings.NameSetting1))
    6.         'Reset all
    7.         My.Settings.Reset()
    8.         Me.Text = My.Settings.NameSetting1
    9.     End Sub
    10. End Class
    11.  
    12. '....
    13.  
    14. Imports System.Configuration
    15.  
    16. Namespace My
    17.     Partial Class MySettings
    18.  
    19.         Public Overloads Sub Reset(SettingName As String)
    20.             For Each Prop In Me.Properties.OfType(Of SettingsProperty).Where(Function(x) x.Name = SettingName)
    21.                 CallByName(Me, Prop.Name, CallType.Let, Prop.DefaultValue)
    22.             Next
    23.         End Sub
    24.  
    25.     End Class
    26. End Namespace

    Kris

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.