Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Sticky' Control Level Validation Not working as expected

Status
Not open for further replies.

RebelFox

Programmer
Jun 16, 2002
62
0
0
GB
I've been reading up on how to use validation on forms.

I need to validate a field has been filled in so I have
used the 'Validating' event that is called just before my form textbox loses focus.

If the field is blank, the focus stays on the textbox and an
appropriate error message is displayed.

The problem is that if a user clicks the 'exit' button i do not want the focus to be returned to the textbox, even if it is not filled in.

According to everything I have read, I can bypass the validating event on my textbox by setting the 'CausesValidation' property on my Exit button to false
at design time.

The rouble is, it doesn't have any effect.
If my textbox is blank and I click on my exit button to close the form, the validation keeps me on the textbox control.

Anybody any idea where I'm going wrong?


Private Sub MyTextBox_Validating(ByVal sender As Object _
ByVal e As System.ComponentMode1.cancelEventArgs) _
handles MyTextBox.Validating

If MyTextBox.text = "" Then
e.cancel = true
End if

End Sub
 
Good idea but not the answer.
I checked the form properties and the CausesValidation was indeed true for the form. But even with it set to False I still get the same problem.

its a frustrating little problem.
 
Per help, you also need to add e.Cancel = false to your form's Closing() event. See help under the title:

Validation of Control Data on Windows Forms
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top