Jump to content

c# coding error trapping help

JimmyJimJam

so I'm trying to error trap a certain piece of code so that you cannot continue without the combo boxes having data selected in them.

any time I try to continue the error message saying for me to select the data comes up even after I have selected it.

 

public bool IsPresentCBO(ComboBox cbo, string name)
        {
            if (cbo.SelectedItem == null);
            {
                MessageBox.Show("Please select one of the following - " + name);
                cbo.Focus();
                return false;
            }
            return true;
        }
        public bool IsValidData()
        {
            return
 
            IsPresentCBO(cbo_class, "seating class ") &&
            IsPresentCBO(cbo_location, "location ") &&
            IsPresentCBO(cbo_tickets, "tickets ");
        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            string location = cbo_location.SelectedItem.ToString();
            int price = 0;
            switch (location)
            {
                case "Tokyo":
                    price = 900;
                    break;
                case "London":
                    price = 120;
                    break;
                case "Paris":
                    price = 260;
                    break;
                case "New york":
                    price = 700;
                    break;
            }
            string Flightclasses = cbo_class.SelectedItem.ToString();
            int price1 = 0;
            switch (Flightclasses)
            {
                case "Economy":
                    price = 50;
                    break;
                case "First class":
                    price = 120;
                    break;
                case "Business":
                    price = 80;
                    break;
            }
            decimal totalprice = price + price1 * price;
            txt_flightcost.Text = totalprice.ToString("c");

 

Capture.PNG

Link to comment
Share on other sites

Link to post
Share on other sites

Where's the code segment where you use  IsValidData()?

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×