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.
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();
}
you have nothing in your code that is stopping invalid entires
ASKER
How would I do that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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