Hi there guys I need help in my c# program.

I have an enrollment form for students and I can't add the additional charge of 1500 for male students.

As you can see in my attachment, the textbox below which contains 9164 must be 10664 if a student is male. 9164 is just the total of the extra fees the school charges, no subject units' fees are added there yet. Any ideas how I get that combobox to add 1500 if the item selected is male?

Attachments c#pgram.jpg 28.67 KB

Try with this:

bool bMaleSelected;
        public Form1()
        {
            InitializeComponent();
            textBox1.Text = "9164";
            comboBox1.Items.AddRange(new string[] { "male", "female" });
            comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex > -1)
            {
                int intValue = 0;
                if (int.TryParse(textBox1.Text.Trim(), out intValue))
                {
                    if (comboBox1.SelectedItem.ToString() == "male")
                    {
                        if (!bMaleSelected)
                        {
                            textBox1.Text = (intValue + 1500).ToString();
                            bMaleSelected = true;
                        }
                    }
                    else if (comboBox1.SelectedItem.ToString() == "female")
                    {
                        if (bMaleSelected)
                        {
                            textBox1.Text = (intValue - 1500).ToString();
                            bMaleSelected = false;
                        }
                    }
                }
            }
        }

Edited 5 Years Ago by Mitja Bonca: n/a

This article has been dead for over six months. Start a new discussion instead.