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?

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;
                        }
                    }
                }
            }
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.