vendredi 12 juillet 2019

if and else if statement not working as intended (c# Winforms)

so i have an if...else if statement that specifies which TextBoxes should be filled, but it doesn't work as very well, here is my code:

private void bunifuFlatButton1_Click(object sender, EventArgs e)
    {
        userform2 form2 = new userform2();
        var combos = new[] { comboBox1, comboBox2, comboBox4 };


         if (form2.comboBox3.SelectedItem=="Inside of Iraq" && combos.Any(cb => cb.SelectedItem == null) || (jTextBox10.TextValue == "" && jTextBox8.TextValue == "") || jTextBox6.TextValue == "")
            {
                MetroFramework.MetroMessageBox.Show(this, "", "Please Enter All the Fields as Required", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
         else if (form2.comboBox3.SelectedItem == "Outside of Iraq" || (jTextBox10.TextValue == "" && jTextBox8.TextValue == "") || jTextBox12.TextValue == "")
         {
             MetroFramework.MetroMessageBox.Show(this, "", "Please Enter All the Fields as Required", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }


    }

the problem here is the statement that is written in the else if block doesn't work, when i fill the TextBoxesi specified in the statement and i click Next Button, the MessageBox shows up,but when i delete the else if statement and i write only an if statement it works perfectly fine am i doing anything wrong that this is happening? thanks for the help

Aucun commentaire:

Enregistrer un commentaire