Problems with Leave event validation.

  • Thread starter Thread starter Rob Bradford
  • Start date Start date
R

Rob Bradford

All.

I'm fairly new to VB.Net, and VB in general so please bear with me.

I have form with two or three controls that require validation on
exit. I have done this by using the "leave" event of the objects
conserned, it all works very well.

Except if the user clicks on the exit button whilst in one of these
fobjects/fields . Clicking the Exit button executes the validataion. I
just want the form to exit without executing the validation.

How do I achieve this?

Thanks in advance.

Rob_B.
 
Hi Rob,

I had a similar problem exiting any form that required validation in any
way. Rulin Hong answered me with the code below. It's a bit cryptic
(including a typo or two), but it works fine.

Let me know if you can't follow it.

HTH,

Bernie Yaeger
---------------------
Hey Rulin,

Excellent code - I've been looking for this for some time! Tx
Bernie Yaeger

Rulin Hong said:
Add following code in winform:

Private NeedValidting As Boolean = True
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If NeedValidting Then
'Do Validating
End If
End Sub

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = &H10 Then
NeedValidting = False
End If
MyBase.WndProc(m)
End Sub
----------------
 
Rob Bradford <[email protected]>'s wild thoughts were
released on Sat, 25 Sep 2004 07:20:33 +0000 (UTC) bearing
the following fruit:
All.

I'm fairly new to VB.Net, and VB in general so please bear with me.

I have form with two or three controls that require validation on
exit. I have done this by using the "leave" event of the objects
conserned, it all works very well.

Except if the user clicks on the exit button whilst in one of these
fobjects/fields . Clicking the Exit button executes the validataion. I
just want the form to exit without executing the validation.

How do I achieve this?

May I suggest you change your code.

Don't validate each control in the way you are doing, it's a
PITA for keyboard users.

Write one validation routine and call it from the OK button.

Not only does it make maitenance of the validation easier,
it solves your problem and makes your application easier to
use.


Thanks in advance.

Rob_B.


Jan Hyde (VB MVP)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top