vendredi 20 février 2015

Need help on Visual C++ windows form application error provider


I am creating several windows forms using Visual C++, and I add the ErrorProvider component into the forms for the forms' validation.


For the other components such as TextBox, ComboBox, RadioButton, ..., it works fine with ErrorProvider. The ErrorProvider pops up with the flashing red icons and theirs error messages when the forms' fields are blank, and the red icons will go away when those blank fields are filled in. But with MaskedTextBox component, the ErrorProvider pops up when the field is blank, but it keeps flashing the red icon with the same error message when the field is filled out, and I cannot keep completing the below blank fields (emailAddress field in this case) for the forms.


Below is my code:



else if ((mtb_dob->Mask == "00/00/0000") && ((tb_emailAddress->Text == "" || tb_emailAddress->Text != "") || (tb_usrnm->Text == "" || tb_usrnm->Text != "") ||
(tb_pwd->Text == "" || tb_pwd->Text != "") ||
(tb_confirmPwd->Text == "" || tb_confirmPwd->Text != ""))) {
errorProvider1->Clear();
errorProvider1->SetError(mtb_dob, "'Date of Birth' is required!");
}
else if (tb_emailAddress->Text == "" && ((mtb_dob->Text == "" || mtb_dob->Text != "") || (tb_usrnm->Text == "" || tb_usrnm->Text != "") ||
(tb_pwd->Text == "" || tb_pwd->Text != "") ||
(tb_confirmPwd->Text == "" || tb_confirmPwd->Text != ""))) {
errorProvider1->Clear();
errorProvider1->SetError(tb_emailAddress, "'Email Address' is required!");
}


Or if I change from 'mtb_dob->Text' to 'mtb_dob->Mask', the red icon still flashes with the same error message:



else if ((mtb_dob->Mask == "00/00/0000") && ((tb_usrnm->Text == "" || tb_usrnm->Text != "") ||
(tb_pwd->Text == "" || tb_pwd->Text != "") ||
(tb_confirmPwd->Text == "" || tb_confirmPwd->Text != ""))) {
errorProvider1->Clear();
errorProvider1->SetError(mtb_dob, "'Date of Birth' is required!");
}
else if (tb_emailAddress->Text == "" && ((mtb_dob->Mask == "00/00/0000" || mtb_dob->Mask != "00/00/0000") || (tb_usrnm->Text == "" || tb_usrnm->Text != "") ||
(tb_pwd->Text == "" || tb_pwd->Text != "") ||
(tb_confirmPwd->Text == "" || tb_confirmPwd->Text != ""))) {
errorProvider1->Clear();
errorProvider1->SetError(tb_emailAddress, "'Email Address' is required!");
}


How can I fix the error? Any other properties besides Text & Mask properties for MaskedTextBox that I can use to fix this error? Thanks a lot.




Aucun commentaire:

Enregistrer un commentaire