PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
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

    "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?


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

    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

    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
    Sydney, Australia

    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
    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
    1/2 way accross the galaxy.. and then some

    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
    12. '....
    14. Imports System.Configuration
    16. Namespace My
    17.     Partial Class MySettings
    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
    25.     End Class
    26. End Namespace


Posting Permissions

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


Click Here to Expand Forum to Full Width