Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have some code not working properly for me.
private void menuClearOrder_Click(object sender, EventArgs e)
        {
            this.listBoxEntree.ClearSelected();
            this.menuEntree2.ClearSelected();
            this.comboBox2.SelectedIndex = -1;
            this.comboBox2.Text = " ";
            newOrder.Entree = " ";
            newOrder.Entree2 = " ";
            newOrder.ExtrasSelection = " ";
            comboBox2.Visible = false;
            label2.Visible = false;
            newOrder.DetermineTotalCharges().ToString("");
      
        }





Everything is working right except for clearing the Total Charges. The listBox is cleared, the comboBox is cleared, and it is made invisible. However, when I place a new order, that total is added onto the previous total.
I can't figure out how to clear the total charges when I clear my order. Any help would be appreciated.
Posted
Comments
Killzone DeathMan 10-Sep-12 10:00am    
Maybe i dont understand the question properly...
[no name] 10-Sep-12 10:00am    
You should probably look at whatever your "newOrder" class is doing. I do not think that "newOrder.DetermineTotalCharges().ToString("");" is doing what you think it's doing.

listBoxEntree.Items.Clear();
listBoxEnrtee.Items.Add("MyItem");
 
Share this answer
 
Comments
[no name] 10-Sep-12 10:02am    
???
Killzone DeathMan 10-Sep-12 10:05am    
As I say... maybe i dont understand the question :P
Can you please explain me what you want to do?
Member 9417196 10-Sep-12 10:14am    
I have two listBoxs. One with drinks, one with food. I have a comboBox with special add-ons. When the user clicks the Clear order, everything should be cleared as if the form was just opened. When I click the clear order, everything is clear except for the order Total. Instead, the order total just keeps getting higher, because each item selected it just added on to the previous order. I cant figure out how to clear the total.
Killzone DeathMan 10-Sep-12 10:22am    
Can you exactly tell me what is the order total?

To clear the listBox is "listBox.Items.Clear()" , when you make "this.listBoxEntree.ClearSelected()" only clear the selected...

You say "everything should be cleared as if the form was just opened", then why you just dont reopen the form?
Member 9417196 10-Sep-12 10:25am    
I meant to say everything that the user previously selected should be cleared. So for example, they mess up, but they can clear order and start over.
Heres part of the code, maybe then you can see more of what Im trying to do

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication11
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {


        }

        private void Form1_Load(object sender, EventArgs e)
        {
            newOrder = new Order();
            for (int i = 0; i < newOrder.menuEntree.Length; i++)
            {
                this.listBoxEntree.Items.Add(newOrder.menuEntree[i]);


            }
            for (int i = 0; i < newOrder.menuEntree2.Length; i++)
            {
                this.menuEntree2.Items.Add(newOrder.menuEntree2[i]);

            }

        }

        private void listBoxEntree_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            newOrder.Entree = this.listBoxEntree.Text;
            if (this.listBoxEntree.SelectedItems.Contains("Tea"))
            {
                comboBox2.Visible = true;
                label2.Visible = true;
            }
            newOrder.Entree = this.listBoxEntree.Text;
            if (this.listBoxEntree.SelectedItems.Contains("Coffee"))
            {
                comboBox2.Visible = true;
                label2.Visible = true;
            }

        }

        private void menuDisplayOrder_Click(object sender, EventArgs e)
        {
            MessageBox.Show(newOrder.Entree + "\n"
                            + newOrder.ExtrasSelection
                            + "\n"
                            + newOrder.Entree2 
                            + "\n"
                            + "Current Order");
        }

        private void comboBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            newOrder.ExtrasSelection = this.comboBox2.Text;
        }

        private void menuClearOrder_Click(object sender, EventArgs e)
        {
            this.listBoxEntree.ClearSelected();
            this.menuEntree2.ClearSelected();
            this.comboBox2.SelectedIndex = -1;
            this.comboBox2.Text = " ";
            newOrder.Entree = " ";
            newOrder.Entree2 = " ";
            newOrder.ExtrasSelection = " ";
            comboBox2.Visible = false;
            label2.Visible = false;
            newOrder.DetermineTotalCharges().ToString("");
      
        }

        private void menuSubmitOrder_Click(object sender, EventArgs e)
        {
            MessageBox.Show(newOrder.Entree + "\n" +
                newOrder.ExtrasSelection + "\n" + newOrder.Entree2 + "\n\n\n" + "Total: " +
                newOrder.DetermineTotalCharges().ToString("C"), "Order Submitted");
                
        }

        private void menuExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            newOrder.ExtrasSelection = this.comboBox2.Text;
        }

        private void menuEntree2_SelectedIndexChanged(object sender, EventArgs e)
        {
            newOrder.Entree2 = this.menuEntree2.Text;
        }



    }
}
 
Share this answer
 
Comments
[no name] 10-Sep-12 10:25am    
This is not an answer to your question. You should be using the "Improve question" widget to add content to your question. As I already told you, you should be looking at whatever your "newOrder" class is doing. Your whole issue could probably be resolved by replacing newOrder.DetermineTotalCharges().ToString("");
with
newOrder = new Order();
Member 9417196 10-Sep-12 10:28am    
Im sorry.. new to programming and this website. I know its frustrating for you guys! But you actually fixed my problem. Placing newOrder = new Order(); in the code worked. Thanks a lot!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900