all groups > dotnet windows forms > june 2004 >
You're in the

dotnet windows forms

group:

CausesValidation on Cancel button



CausesValidation on Cancel button jester
6/30/2004 7:04:01 PM
dotnet windows forms:
Re: CausesValidation on Cancel button ClayB [Syncfusion]
7/1/2004 9:18:43 AM
Just something to try. Before you call Me.Close, try setting
Me.CausesValidation = False.

========================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

[quoted text, click to view]
and e.Cancel = True when applicable. My problem is with the Cancel button
(w/c has CausesValidation = False). If I close the form inside the Cancel
button code (i.e., Me.Close), the Validating events of the textboxes fire,
preventing the user from closing the form. I can think of many workarounds
for this (such as introduce a form-level flag var) but I was hoping for a
simpler solution. Thanks in advance =)

Re: CausesValidation on Cancel button downeyt
9/22/2005 6:54:07 AM

If you are using an errorProvider and setting e.Cancel to true whe
validating, then you can force the form to close by overriding th
Closing event and setting e.Cancel to false.

In the modal case, clicking a button that has CausesValidation set t
false does not fire the validating event.

In the modeless case, it does not fire the event when the button i
clicked, but it does fire the event when the Close method is called. I
e.Cancel is set to true during validation, then this will cancel th
closing of the form. The solution is to reset the e.Cancel to fals
after the validation fires. This can be done in the Closing event

--
downey
-----------------------------------------------------------------------
downeyt's Profile: http://www.msusenet.com/member.php?userid=490
View this thread: http://www.msusenet.com/t-186975676
AddThis Social Bookmark Button