Link to home
Start Free TrialLog in
Avatar of Computer Guy
Computer Guy

asked on

Another Class Issue

Hi,

Sending this data to a list box, every time I click submit it makes an index entry even if the data is invalid. When it finally is valid there are several entries before the valid one.

  {
            int IDNumber = 0;
            
            if(nameTextBox.Text == "")
            {
                MessageBox.Show("Invalid Name");
                return;
            }


            if (departmentTextBox.Text == "")
            {
                MessageBox.Show("Invalid Department");
                return;
            }


            if (positionTextBox.Text == "")
            {
                MessageBox.Show("Invalid Position");
                return;
            }

            if (int.TryParse(idNumberTextBox.Text, out IDNumber))
            {
                employee.IdNumber = IDNumber;
            }
            else
            {
                MessageBox.Show("Invalid ID Number");
                return;
            }



        }

 private void addEmployeeButton_Click_1(object sender, EventArgs e)
        {
            Employee myEmployee = new Employee();

            GetEmployeeData(myEmployee);

            employeeList.Add(myEmployee);

            employeeListBox.Items.Add(myEmployee.Name);

            nameTextBox.Clear();
            idNumberTextBox.Clear();
            departmentTextBox.Clear();
            positionTextBox.Clear();
        }

Open in new window

Avatar of plusone3055
plusone3055
Flag of United States of America image

you have nothing in your code that is stopping invalid entires
Avatar of Computer Guy
Computer Guy

ASKER

How would I do that?
ASKER CERTIFIED SOLUTION
Avatar of plusone3055
plusone3055
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm about to call it for the evening in the morning I can post you a good method that would help you with this code