Results 1 to 17 of 17

Thread: [RESOLVED] How to save setting for radio buttons & Checkboxes control in groupboxes ?!

  1. #1

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    Resolved [RESOLVED] How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    Hi…

    I’ve got over than 120 groupboxes in my project which Contains radio buttons & Checkboxes control…

    How can I save & retrieve the selection setting for these huge amounts of groupboxes when close my form and restart it?

    Regards…
    Attached Images Attached Images  

  2. #2
    Addicted Member
    Join Date
    Feb 2010
    Posts
    197

    Re: How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    You could go to the properties for each radiobutton, and on the application settings area (at the top) add a new setting for the 'checked' value. This will save the check states on app exit, and then retrieves them on next run.

    Same for the checkboxes,.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    DragonRoses' advice is sound for the CheckBoxes but you may find that you have issues doing that with the RadioButtons. If that's so, you can still use My.Settings to store the data but you can't bind it. In that case, I'd define an enumeration and store one value for each group of RadioButtons.

  4. #4

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    Re: How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    Quote Originally Posted by DragonRose View Post
    You could go to the properties for each radiobutton, and on the area (at the top) add a new setting for the 'checked' value. This will save the check states on app exit, and then retrieves them on next run.

    Same for the checkboxes,.
    Thanks DragonRose for reply...

    I was looking for Simplified solution for this issue because using application settings and property binding will result quit a long list for each control !

    Regards…

  5. #5

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    Re: How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    Quote Originally Posted by jmcilhinney View Post
    DragonRoses' advice is sound for the CheckBoxes but you may find that you have issues doing that with the RadioButtons. If that's so, you can still use My.Settings to store the data but you can't bind it. In that case, I'd define an enumeration and store one value for each group of RadioButtons.


    Thanks jmcilhinney…

    How can I store the values after defining an enumeration?

    Code:
    Public Enum Skill
            Rad_Average = 1
            Rad_good = 2
            Rad_Excellent = 3
        End Enum
    Could you PLZ give me an example in codes with my issue ?!

    Regards…

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    The following code assumes that the type of My.Settings.Skill1 and My.Settings.Skill2 is your Skill type.
    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         Me.skill1AverageOption.Checked = (My.Settings.Skill1 = Skill.Average)
    5.         Me.skill1GoodOption.Checked = (My.Settings.Skill1 = Skill.Good)
    6.         Me.skill1ExcellentOption.Checked = (My.Settings.Skill1 = Skill.Excellent)
    7.         Me.skill2AverageOption.Checked = (My.Settings.Skill2 = Skill.Average)
    8.         Me.skill2GoodOption.Checked = (My.Settings.Skill2 = Skill.Good)
    9.         Me.skill2ExcellentOption.Checked = (My.Settings.Skill2 = Skill.Excellent)
    10.     End Sub
    11.  
    12.     Private Sub skill1AverageOption_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles skill1AverageOption.CheckedChanged
    13.         My.Settings.Skill1 = Skill.Average
    14.     End Sub
    15.  
    16.     Private Sub skill1GoodOption_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles skill1GoodOption.CheckedChanged
    17.         My.Settings.Skill1 = Skill.Good
    18.     End Sub
    19.  
    20.     Private Sub skill1ExcellentOption_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles skill1ExcellentOption.CheckedChanged
    21.         My.Settings.Skill1 = Skill.Excellent
    22.     End Sub
    23.  
    24.     Private Sub skill2AverageOption_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles skill2AverageOption.CheckedChanged
    25.         My.Settings.Skill2 = Skill.Average
    26.     End Sub
    27.  
    28.     Private Sub skill2GoodOption_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles skill2GoodOption.CheckedChanged
    29.         My.Settings.Skill2 = Skill.Good
    30.     End Sub
    31.  
    32.     Private Sub skill2ExcellentOption_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles skill2ExcellentOption.CheckedChanged
    33.         My.Settings.Skill2 = Skill.Excellent
    34.     End Sub
    35.  
    36. End Class
    37.  
    38.  
    39. Public Enum Skill
    40.     None = 0
    41.     Average
    42.     Good
    43.     Excellent
    44. End Enum
    I included the None value in the enumeration so that no RadioButton would be checked initially. If you want to check a default RadioButton in each group then you may not need that. It's always a good idea to at least consider having the zero value in an enumeration equal to None, Unknown or the like in case there will be times that you need no value to be selected.

  7. #7

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    Re: How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    Thanks jmcilhinney…

    I appreciate your effort and time to help …

    I’ve tried to apply the codes on my project but unfortunately list of errors shows in “Error List”



    Any idea Please…


    Best Regards…
    Last edited by HOTFIX; Jun 7th, 2010 at 11:34 PM. Reason: Issue Sloved !

  8. #8
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    Did you name your radio buttons "skill1GoodOption", "skill1ExcellentOption", "skill1AverageOption", ... as shown in JMC's code?
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  9. #9

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    Re: How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    Quote Originally Posted by stanav View Post
    Did you name your radio buttons "skill1GoodOption", "skill1ExcellentOption", "skill1AverageOption", ... as shown in JMC's code?
    hi stanav...

    After renaming radio buttons controls, I’m still getting some errors:

    "Handles clause requires a WithEvents variable defined in the containing type or one of its base types."

    So in this case this will result long list for radio buttons codes in load event & Subs ...

    Any idea to avoid this case...

    Regards...

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    First up, why are your Settings declared as type Boolean? They need to be your enumeration type.

    As for that error, you've done something wrong. You were NOT supposed to copy and paste my code. This is exactly why I avoid posting code on many occasions. My code was supposed to be an example only. You were supposed to write your own code. You were supposed to create CheckedChanged event handlers for your own RadioButtons and refer to your own RadioButtons in the Load event handler. If you have a lot of RadioButtons then you will have a lot of code. That's life.

  11. #11

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    Re: How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    Quote Originally Posted by jmcilhinney View Post
    First up, why are your Settings declared as type Boolean? They need to be your enumeration type.

    As for that error, you've done something wrong. You were NOT supposed to copy and paste my code. This is exactly why I avoid posting code on many occasions. My code was supposed to be an example only. You were supposed to write your own code. You were supposed to create CheckedChanged event handlers for your own RadioButtons and refer to your own RadioButtons in the Load event handler. If you have a lot of RadioButtons then you will have a lot of code. That's life.



    Thanks jmcilhinney for your support…

    For the setting declaration , I couldn’t see enumeration type in the list so I’m assuming it will be either string or system….,string collection and the values will be enum list ; is it?!

    I’ve fixed my errors related with CheckedChanged event handlers; anyway using your codes example gives me better understanding of the work process for my project…

    Best Regards…

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    Quote Originally Posted by HOTFIX View Post
    For the setting declaration , I couldn’t see enumeration type in the list so I’m assuming it will be either string or system….,string collection and the values will be enum list ; is it?!
    The list contains the most common options, plus a Browse option if you want to use something else. You can then either select your type from the tree or just enter it directly into the text box.

  13. #13
    Addicted Member
    Join Date
    Mar 2010
    Location
    Southeast Michigan
    Posts
    155

    Re: How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    Just curious about the enumeration type for settings. I don't seem to be able to set the setting type to my enumeration. Entering it into the textbox tells me the type is not defined?
    Dave

    Helpful information I've found here so far : The Definitive "Passing Data Between Forms" : Restrict TextBox to only certain characters, numeric or symbolic :
    .NET Regex Syntax (scripting) : .NET Regex Language Element : .NET Regex Class : Regular-Expressions.info
    Stuff I've learned here so far : Bing and Google are your friend. Trying to help others solve their problems is a great learning experience

  14. #14
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    Have you used the fully qualified name? For instance, if your project is called MyProject then the root namespace will also be MyProject by default. If you enumeration is called MyEnumeration and you have specified a namespace for it, it will be a member of the root namespace. As such, the fully qualified name is MyProject.MyEnumeration. You'll have to adjust that to use the actual names for you case. Plus, if you've changed the root namespace or added the type to a different namespace, which I doubt, then you'd have to adjust the fully qualified name accordingly.

  15. #15

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    Re: How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    Hi...

    Enum Statement (Visual Basic)

    The Enum statement can declare the data type of an enumeration. Each member takes the enumeration's data type. You can specify Byte, Integer, Long, SByte, Short, UInteger, ULong, or UShort

    With my project case it working only by above type list !

    Regards...

  16. #16
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    Quote Originally Posted by HOTFIX View Post
    Hi...

    Enum Statement (Visual Basic)




    With my project case it working only by above type list !

    Regards...
    Then you did it wrong. Here's a working demo.
    Attached Files Attached Files

  17. #17

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    Resolved Re: How to save setting for radio buttons & Checkboxes control in groupboxes ?!

    Quote Originally Posted by jmcilhinney View Post
    Then you did it wrong. Here's a working demo.
    Maybe it's the wrong way but it seem to be work without any errors...


    Regards...
    Last edited by HOTFIX; Jun 7th, 2010 at 11:38 PM. Reason: Issue Sloved !

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