I am working on a project that uses an ErrorProvider for form validation. For the form reset button and exit buttons, validation=false to allow button functionality with form validation errors. What is the best way to have menu clicks not cause validation as well. For example, under the File menu I have Compute, Reset and Exit. Right now all menu buttons cause validation. The code for the menu Buttons is
CODE
btnCompute.PerformClick()
this works for the Compute button as I want it to validate.
I am looking for a way to turn validation off for the other menu items. I have tried placing
CODE
causesValidation = False
under the menuItem clickEvent but it doesn't work, I have to go about it as follows. For the reset button I have to manually set the error to nothing for each txtBox.
CODE
btnReset.PerformClick()
Me.ErrorProvider1.SetError(Me.txtName, "")
Me.ErrorProvider1.SetError(Me.txtPayRate, "")
Me.ErrorProvider1.SetError(Me.txtHours, "")
Me.ErrorProvider1.SetError(Me.mtxtID, "")
Me.ErrorProvider1.SetError(Me.txtDept, "")
For the Exit button I cannot use performClick at all, I have to enter all the code for the exit button.
CODE
Dim messageString As String = "Do you really want to close the application?"
Dim btnDialogResult As MsgBoxResult
btnDialogResult = MsgBox(messageString, MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2 + MsgBoxStyle.Question, "Quit?") 'MsgBox.Show(messageString, "Quit?", MsgBoxButtons.YesNo, MsgBoxIcon.Question, MsgBoxDefaultButton.Button2)
If btnDialogResult = MsgBoxResult.Yes Then
End
End If
So I guess the question is there one easy way to cancel validation for the menu items when using the code
CODE
btnExit.PerformClick()
For the record, I'm using vb.net VS2008 .net Framework 3.5 sp1