Results 1 to 4 of 4

Thread: Setting Checkbox Values

  1. #1

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211

    Setting Checkbox Values

    Im making a program that lets you select a color from a list of checkboxes. There are 3 lbls and 3 groups of checkboxes all with the same colors, this all works fine but i have made a function to save the colors that were in the checkboxes int he my.settings area. This too works fine and it loads them back but the only problem is i dont know how to select the right checkbox for what color is in the coresponing label.

    So lets just say the user selects green from box1, label1's backcolor will turn green. If he has save settings checked then it will have the backcolor in my.settings. On load it will load the color from my.settings and it all works great but how do i select the green checkbox again? I know i could do alot of If Thens to make it work ( If my.settings.box1 = green then chkb1green.checked = true) but that would be 18 if statements so i was tring to fing a simpler way

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,192

    Re: Setting Checkbox Values

    First of all, I don't see that CheckBoxes are the correct control to be using here. Surely it should be RadioButtons because if each group of three options relates to one Label then only one selection can be made at a time. That's exactly what RadioButtons are for.

    Secondly, you don't need any If statements at all, e.g.
    vb.net Code:
    1. option1.Checked = (My.Settings.Box1BackColour = Color.Green)
    The bit inside the parentheses evaluates to a Boolean that indicates whether the value is Green, and that Boolean determines whether the option is checked or not. You simply change the colour for each option.

  3. #3

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211

    Re: Setting Checkbox Values

    Thanks for the help!
    Last edited by Motoxpro; Oct 26th, 2007 at 08:03 AM.

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

    Re: Setting Checkbox Values

    Huh? I've shown you how to do it with just three settings. What's the problem?

    If these are menu items then I don't think they're CheckBoxes at all. They're probably ToolStripMenuItems. If they are CheckBoxes then you must have created your own control host, which can be done just as easily RadioButtons.

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