private Boolean CheckForValidation() { //check if the field is not empty if (ProductId.Text.Length == 0) { ProductId.Focus(); error.SetError(ProductId, MessageBox.Show("Please enter the Product Id", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error).ToString()); return(false); } else if (CheckForProductCode() == false) { ProductId.Focus(); error.SetError(ProductId, MessageBox.Show("Product id entered does not match the database ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error).ToString()); return(false); } return(true); }