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

LVL 3
Computer GuyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

plusone3055Commented:
you have nothing in your code that is stopping invalid entires
0
Computer GuyAuthor Commented:
How would I do that?
0
plusone3055Commented:
well what you have above your button click method would be a good start but you have it outside of your button method so it's not stopping any of your invalid entries
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
plusone3055Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.