Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,242 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,249 people online right now. Registration is fast and FREE... Join Now!




ErrorProvider problems

 
Reply to this topicStart new topic

ErrorProvider problems

r3tic
10 Oct, 2008 - 07:52 PM
Post #1

New D.I.C Head
*

Joined: 22 Sep, 2008
Posts: 15


My Contributions
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
User is offlineProfile CardPM
+Quote Post

magicmonkey
RE: ErrorProvider Problems
11 Oct, 2008 - 12:06 PM
Post #2

D.I.C Regular
***

Joined: 12 Sep, 2008
Posts: 413



Thanked: 68 times
My Contributions
I hate validation events... I always pull my hair out when I try to use them, however try to turn off the autovalidation before performing your code that changes a bunch of textboxes then turn it back on, or just turn it off before you close the form.

vb

Me.AutoValidate = Windows.Forms.AutoValidate.Disable 'Off

'My Code that changes a bunch of stuff

Me.AutoValidate = Windows.Forms.AutoValidate.EnablePreventFocusChange 'On


vb

Me.AutoValidate = Windows.Forms.AutoValidate.Disable 'Off
Me.Close 'Exit

User is offlineProfile CardPM
+Quote Post

r3tic
RE: ErrorProvider Problems
11 Oct, 2008 - 12:40 PM
Post #3

New D.I.C Head
*

Joined: 22 Sep, 2008
Posts: 15


My Contributions
Works like a charm! thanks
User is offlineProfile CardPM
+Quote Post

r3tic
RE: ErrorProvider Problems
28 Oct, 2008 - 05:51 AM
Post #4

New D.I.C Head
*

Joined: 22 Sep, 2008
Posts: 15


My Contributions
I have found another even easier method. When you Code the button you can modify the handles clause to accept the click event of the menu item as well. You change this code
CODE
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
         code that does stuff
End Sub

to this code
CODE
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click, mnuExit.Click
         code that does stuff
End Sub

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 03:43AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month