Click here to Skip to main content
15,500,838 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to build a Restaurant Bill Calculator for class, but I am experiencing a few errors that I can't figure out how to fix. The Error CS1026 states in the error list that it was "expected". The Error CS1061 states in the Error list that 'TextBox' does not contain a definition for 'Items' and no extension method 'Items' accepting a first argument of type 'TextBox' could be found (are you missing a using directive or an assembly reference?). Items is listed in the ComboBoxes... I can't figure out how to fix these errors Dx. Please assist me and thank you!
Here is my coding for the Restaurant Bill Calculator:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Restaurant_Bill_Calculator
{

    public partial class RestaurantBillCalculator : Form
    {
        public struct Orders
        {
            public string item;
            public double price;
        }

        const double TAX = 0.06; //6% tax
        Orders order = new Orders();
        static double subtotal = 0;
        static double totalTaxes = 0;
        static double total = 0;
        string finalBill = "FINAL BILL: \n";

        public RestaurantBillCalculator()
        {
            InitializeComponent();
        }

        private void getValues(string custOrder)
        {
            order.item = custOrder.Split('$')[0];
            order.price = Convert.ToDouble(custOrder.Split('$')[1];
            Output.Items.Add("Price: " + order.price);
            finalBill += "Ordered Item: " + order.item + "\nPrice: " + order.price.ToString("C2") + "\n";
            updateBill();
        }

        private void updateBill()
        {
            subtotal += order.price;
            total += order.price + (order.price * TAX);
            totalTaxes += order.price * TAX;
            {

            }

            Output.Items.Clear();
            Output.Items.AddRange(finalBill.Split('\n'));
            Output.Items.Add("Subtotal: " + subtotal.ToString("C2"));
            Output.Items.Add("Tax: " + totalTaxes.ToString("C2"));
            Output.Items.Add("Total: " + total.ToString("C2"));
        }

        private void RestaurantBillCalculator_Load(object sender, EventArgs e)
        {

        }

        private void dropdownSelection(object sender, EventArgs e)
        {
            if (sender == cmbdrinks)
                getValues(cmbdrinks.SelectedItem.ToString());
            else if (sender == cmbappetizers)
                getValues(cmbappetizers.SelectedItem.ToString());
            else if (sender == cmbmaincourses)
                getValues(cmbmaincourses.SelectedItem.ToString());
            else
                getValues(cmbdrinks.SelectedItem.ToString());
        }

        private void Output_TextChanged(object sender, EventArgs e)
        {
        }

        private void Clear_Click(object sender, EventArgs e)
        {
        }
    }
}


What I have tried:

I have tried to find a solution online, but no solution has fit my issue...
Posted
Updated 31-Oct-16 7:11am
v2
Comments
ZurdoDev 31-Oct-16 11:53am     CRLF
You need to tell us which line of code causes the error and what the full error is. 'TextBox' does not contain a definition for 'Items' - This means that you have a textbox somewhere and are trying to access Items on it, but Items is not a valid property or method on a Textbox.
Member 12825311 31-Oct-16 11:59am    
Oops I apologize... Error CS1026 is on line 37 and Error CS1061 is on lines 38, 52, 53, 54, 55, and 56. The error CS1061 doesn't recognize 'Items' which doesn't make any sense because 'Items' is in the description of the ComboBoxes.
phil.o 31-Oct-16 12:07pm    
Apparently Output is a TextBox, not a ComboBox.
Member 12825311 31-Oct-16 12:11pm    
Yeah Output is the textbox, but I was following a code someone had given me and they stated to use Output.Items.. They stated that if I use Output.Items that it would take the Items from the ComboBox and put it inside the TextBox for calculating, but I guess their information was incorrect lol.

1 solution

Double check what type of control "Output" is. I think you'll find it is a textbox, not a combobox. And a TextBox does not have an Items property.

And line 37 - you're missing a closed bracket. You have two open brackets, and only one closed.
 
Share this answer
 
Comments
Member 12825311 31-Oct-16 12:30pm    
I know Output is a TextBox, but I was told to use that code because it will take the information from the ComboBoxes and put them into the TextBoxes for calculating. Thank you for the missing closed bracket, didn't realize I was missing one.
Midi_Mick 31-Oct-16 12:39pm    
But a TextBox does not have an Items property. If it is a multi-line textbox, you will have to add all the info with to the Output.Text property with a newline ('\n') separator. However, if you don't need to edit the text, I'd possibly look at using a ListBox control instead - that has the Items property you're using.
Member 12825311 31-Oct-16 12:45pm    
Thank you! I appreciate it so much! They had told me the wrong information.
Midi_Mick 31-Oct-16 13:10pm    
No worries - happy to help

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



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