Results 1 to 3 of 3

Thread: Changing Labels

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2012
    Posts
    25

    Changing Labels

    For each order, the user selects a main course item and the application displays the associated add-on items. Then, the user can select zero or more of these add-ons.


    My Question is how do I get the check boxes text to change if you will when the user selects like pizza, instead of having it show lattuce and such for hamburgers I want it to show toppings. These are the add-on's that should be displayed for humburger, pizza or salad.
    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";
    
    
            }
    Attached Images Attached Images  
    Last edited by QuestionPlease; Nov 6th, 2012 at 09:29 PM.

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

    Re: Changing Labels

    Firstly, 'TheChecked' is a bad name for that method. Like everything, that method should have a name that describes what it does, e.g. 'ClearAddOnSelections'.

    In the CheckedChanged event handlers for your RadioButtons, you should not be doing anything at all if the Checked property of the relevant RadioButton is False. If it's True then you should call your method to clear the selections from the CheckBoxes and then set the Text of each one as appropriate. In the method that clears the CheckBoxes, there's no point testing anything or returning anything. You just need three lines: one to uncheck each CheckBox. That's it, that's all.

    As for your Place Order button, the Click event handler for that is all messed up because you have got If statements inside each other. There should not be any If statements inside any other If statements. You start by declaring a variable for the main item price, the single add-on price and the total add-on price. You then use an If..ElseIf statement to test each RadioButton to see which is checked and set the main item price and single add-on price appropriately. Then you use an If statement for each CheckBox and, for each one that's checked, you add the single add-on price to the total add-on price. The total add-on price will then be zero, one, two or three times the single add-on price. Once that's done, your subtotal is the main item price plus the total add-on price.
    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

  3. #3
    New Member
    Join Date
    Dec 2011
    Posts
    7

    Re: Changing Labels

    I got the texts to change and clear.. just stuck now getting the place order button to add everything

    private void rdoHamburger_CheckedChanged(object sender, EventArgs e)
    {
    ResetCheckedText();
    groupBoxAdd.Text = "Add-on items ($.75/each)";
    checkBox1.Text = "Lettuce, tomato, and onions";
    checkBox2.Text = "Mayonnaise and mustard";
    checkBox3.Text = "French fries";
    }

    private void rdoPizza_CheckedChanged(object sender, EventArgs e)
    {
    ResetCheckedText();
    groupBoxAdd.Text = "Add-on Items ($ .50/each)";
    checkBox1.Text = "Pepperoni";
    checkBox2.Text = "Sausage";
    checkBox3.Text = "Olives";
    }

    private void rdoSalad_CheckedChanged(object sender, EventArgs e)
    {
    ResetCheckedText();
    groupBoxAdd.Text = "Add-on Items ($ .25/each)";
    checkBox1.Text = "Croutons";
    checkBox2.Text = "Bacon bits";
    checkBox3.Text = "Bread sticks";
    }


    private void ResetCheckedRadio()
    {
    rdoHamburger.Checked = false;
    rdoPizza.Checked = false;
    rdoSalad.Checked = false;
    }


    private void ResetCheckedText()
    {


    checkBox1.Checked = false;
    checkBox2.Checked = false;
    checkBox3.Checked = false;

    }

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