Results 1 to 13 of 13

Thread: How to display Check Box Text

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2012
    Posts
    25

    How to display Check Box Text

    My Question is how do I get the check boxes text to display the addons for meals below
    Add-ons
    • For a hamburger, the three add-on items are: (1) Lettuce, tomato, and onions; (2) Mayonnaise and mustard; and (3) French fries. The price of each is 75 cents.
    • For a pizza, the three add-on items are: (1) Pepperoni, (2) Sausage, and (3) Olives. The price of each is 50 cents.
    • For a salad, the three items are (1) Croutons, (2) Bacon bits, and (3) Bread sticks. The price of each is 25 cents

    my code isn't showing anything on the form
    HTML Code:
    private void hamburger_CheckChanged(object sender, System.EventArgs e)
            {
                if (radioHamburger.Checked == true)
                    ResetChecked();
    
                groupBox2.Text = " Add-on Items ($ .75/each)";
                checkBox1.Text = "Lettuce, tomato, and onions";
                checkBox2.Text = "Mayonnaise and mustard";
                checkBox3.Text = "French fries";
            }
    
            private void pizza_CheckChanged(object sender, System.EventArgs e)
            {
                if (radioPizza.Checked == true)
                    ResetChecked();
                groupBox2.Text = "Add-on Items ($ .50/each)";
                checkBox1.Text = "Pepperoni";
                checkBox2.Text = "Sausage";
                checkBox3.Text = "Olives";
    
            }
    
            private void salad_CheckChanged(object sender, System.EventArgs e)
            {
                if (radioSalad.Checked == true)
                    ResetChecked();
                groupBox2.Text = "Add-on Items ($ .25/each)";
                checkBox1.Text = "Croutons";
                checkBox2.Text = "Bacon bits";
                checkBox3.Text = "Bread sticks";
    
    
            }
    this is how the check box's should display the addons(text) so if the user clicks another radio botton the check box text changes to the addons for that meal.
    Name:  lunch.png
Views: 165
Size:  14.6 KB
    and this is what mine is displaying no text?
    Name:  pic.PNG
Views: 189
Size:  16.8 KB

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

    Re: How to display Check Box Text

    Are you sure that those methods are actually handling the appropriate events? Did you paste that code into the code window or did you create the event handlers from the design window?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2012
    Posts
    25

    Re: How to display Check Box Text

    No I didn't paste the code in the code window, I don't know why it isn't working???
    Do I Have to set something inthe the Form design property settings??

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

    Re: How to display Check Box Text

    Do you know for a fact that the code is being run? Place a breakpoint (F9) on each event handler and then try selecting the RadioButtons and see if it is hit.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2012
    Posts
    25

    Re: How to display Check Box Text

    just tried it, no their not running what should I do??

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

    Re: How to display Check Box Text

    In that case they are not handling the events, which means that either you didn't generate them from the designer or else (and this is quite likely in this case) at some point you cut and pasted the controls from one container to another. Cutting is equivalent to deleting, so the link would be lost at the point. To reattach an event handler, select a control in the designer, open the Properties window, click the Events button, select the appropriate event and then select the appropriate method from the drop-down list.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Apr 2012
    Posts
    25

    Re: How to display Check Box Text

    I decided to put the check box text change in the form load but when I select another radio box it doesn't change and if I add and else instead of if in the second if it wont let me???
    Code:
    private void Form1_Load(object sender, EventArgs e)
            {
                {
                    if (radioHamburger.Checked == true)
                        ResetChecked();
                    groupBox2.Text = "Add-on Items ($ .75/each)";
                    checkBox1.Text = "Lettuce, Tomato, and Onions";
                    checkBox2.Text = "Mayonnaise and Mustard";
                    checkBox3.Text = "French Fries";
    
                }
                {
                    if (radioSalad.Checked == true)
                        ResetChecked();
                    groupBox2.Text = "Add-on Items ($ .25/each)";
                    checkBox1.Text = "Croutons";
                    checkBox2.Text = "Bacon bits";
                    checkBox3.Text = "Bread sticks";
    
    
                }
                {
                    if (radioSalad.Checked == true)
                        ResetChecked();
                    groupBox2.Text = "Add-on Items ($ .25/each)";
                    checkBox1.Text = "Croutons";
                    checkBox2.Text = "Bacon bits";
                    checkBox3.Text = "Bread sticks";
    
    
                }
            }
        }
    }

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2012
    Posts
    25

    Re: How to display Check Box Text

    I decided to put the check box text change in the form load but when I select another radio box it doesn't change and if I add and else instead of if in the second if it wont let me???
    Code:
    private void Form1_Load(object sender, EventArgs e)
            {
                {
                    if (radioHamburger.Checked == true)
                        ResetChecked();
                    groupBox2.Text = "Add-on Items ($ .75/each)";
                    checkBox1.Text = "Lettuce, Tomato, and Onions";
                    checkBox2.Text = "Mayonnaise and Mustard";
                    checkBox3.Text = "French Fries";
    
                }
                {
                    if (radioSalad.Checked == true)
                        ResetChecked();
                    groupBox2.Text = "Add-on Items ($ .25/each)";
                    checkBox1.Text = "Croutons";
                    checkBox2.Text = "Bacon bits";
                    checkBox3.Text = "Bread sticks";
    
    
                }
                {
                    if (radioSalad.Checked == true)
                        ResetChecked();
                    groupBox2.Text = "Add-on Items ($ .25/each)";
                    checkBox1.Text = "Croutons";
                    checkBox2.Text = "Bacon bits";
                    checkBox3.Text = "Bread sticks";
    
    
                }
            }
        }
    }

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

    Re: How to display Check Box Text

    Of course it doesn't change. The Load event of the form is raised only when the form loads. If you want to do something when the Checked property of the RadioButtons changes then you have to handle the event that is raised in that case, i.e. the CheckedChanged event of the RadioButtons. Go back to your original code and do as I instructed and it will work.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Apr 2012
    Posts
    25

    Re: How to display Check Box Text

    so how do I exactly do that do I wire the controls with the textchanged event
    Name:  ghj.PNG
Views: 138
Size:  46.2 KB

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

    Re: How to display Check Box Text

    Um, you don't. You do what I told you to do:
    If you want to do something when the Checked property of the RadioButtons changes then you have to handle the event that is raised in that case, i.e. the CheckedChanged event of the RadioButtons.
    That's why your original methods each had a name that consisted of the name of a one of the RadioButtons combined with '_CheckedChanged'.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Apr 2012
    Posts
    25

    Re: How to display Check Box Text

    thanks, that was dumb of me

    Your awesome by the way thanks again!!!!

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

    Re: How to display Check Box Text


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