473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Avoiding validation when closing a window...

Tom
How is the best way to avoid validation when closing a
window? For instance, I have a Windows Forms window which
has a validation event for a text box. However, if one
enters invalid data in then and then attempts to close the
window (either via my custom 'Close' box or by clicking the
close 'X' in the upper right window corner), the validation
event still triggers and it tells the user that they have
invalid data. Which of course means they need to clear that
data out then close the window.

Sure, I could trap the close event (both in my custom CLOSE
box and also via WndProc), set a form level 'Closing'
variable and check that in my validate code, but there has
GOT to be an easier way. Why does Windows insist on firing
the validate event when a window is closing?

Is there no easier way to avoid the Validate event when
closing? Thanks.

Tom
--

Nov 21 '05 #1
2 2994

Tom wrote:
How is the best way to avoid validation when closing a
window? For instance, I have a Windows Forms window which
has a validation event for a text box. However, if one
enters invalid data in then and then attempts to close the
window (either via my custom 'Close' box or by clicking the
close 'X' in the upper right window corner), the validation
event still triggers and it tells the user that they have
invalid data. Which of course means they need to clear that
data out then close the window.

Sure, I could trap the close event (both in my custom CLOSE
box and also via WndProc), set a form level 'Closing'
variable and check that in my validate code, but there has
GOT to be an easier way. Why does Windows insist on firing
the validate event when a window is closing?

Is there no easier way to avoid the Validate event when
closing? Thanks. From the help:


Closing The Form and Overriding Validation
A side effect of the control maintaining focus when data is invalid is
that it is impossible to close the parent form in any of the usual ways
you close a form:

* Clicking the Close box
* Via the System menu that appears when you right-click the title bar
* Calling the Close method programmatically
However, in some cases, you might want to allow the user to close the
form regardless of whether the values in the controls are valid. You
can override validation and close a form that still contains invalid
data by creating a handler for the form's Closing event. In the event,
set the Cancel property to False. This forces the form to close.

Note If you force the form to close in this way, any information in
the controls that has not already been saved is lost.
Note Modal forms do not validate the contents of controls when
closed. You can still use control validation to lock focus to a
control, but you do not need to be concerned with the behavior with
regard to closing the form.

--
Larry Lard
Replies to group please

Nov 21 '05 #2
Tom
Larry: Thanks for the info... This works, yet it doesn't
work. Yes, it does cause the form the end even with invalid
data in a field; however the validation routine still runs
so you still get an error message (then the form closes).
Again, although this works it is still ugly. I would rather
just have it close the window and NOT give any error
routine.

Too bad there isn't any way to actually look to see if a
window is closing from the validation routine.

Tom
Larry Lard wrote:

Tom wrote:
How is the best way to avoid validation when closing a
window? For instance, I have a Windows Forms window
which has a validation event for a text box. However,
if one enters invalid data in then and then attempts to
close the window (either via my custom 'Close' box or
by clicking the close 'X' in the upper right window
corner), the validation event still triggers and it
tells the user that they have invalid data. Which of
course means they need to clear that data out then
close the window.

Sure, I could trap the close event (both in my custom
CLOSE box and also via WndProc), set a form level
'Closing' variable and check that in my validate code,
but there has GOT to be an easier way. Why does Windows
insist on firing the validate event when a window is
closing?

Is there no easier way to avoid the Validate event when
closing? Thanks.

From the help:


Closing The Form and Overriding Validation
A side effect of the control maintaining focus when data
is invalid is that it is impossible to close the parent
form in any of the usual ways you close a form:

* Clicking the Close box
* Via the System menu that appears when you right-click
the title bar * Calling the Close method programmatically
However, in some cases, you might want to allow the user
to close the form regardless of whether the values in the
controls are valid. You can override validation and close
a form that still contains invalid data by creating a
handler for the form's Closing event. In the event, set
the Cancel property to False. This forces the form to
close.

Note If you force the form to close in this way, any
information in the controls that has not already been
saved is lost. Note Modal forms do not validate the
contents of controls when closed. You can still use
control validation to lock focus to a control, but you do
not need to be concerned with the behavior with regard to
closing the form.


--

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Mike | last post by:
I've been trying for the past week to put a simple code together. I have done a LOT of searching, found scripts showing the functions I would like to use, however when I mix them it all goes wrong,...
2
by: Derek | last post by:
Hello: I want to capture the event when a browser is closing, to give to the user the posibility of close or no this browser. When the browser is closing, this show a confirm window with two...
10
by: Tom Szabo | last post by:
Is there an event when that triggers when the window is closing.... I am talking about when the user clicks on the cross on the right top corner of the window!!!
6
by: MickG | last post by:
Hi, I am trying to validate these values, this seems to work fine for the phone number and name but I am trying to get the program to fail to submit and set the focus on the date when 2006 is...
22
by: Charles Law | last post by:
Could someone please explain to me, in words of one syllable or less, how I get the Validating event to fire for a form. I have a form with one text box, and two buttons: OK and Cancel. I have...
2
by: Tom | last post by:
I have written a validatedTextBox class which inherits from textBox. I've added code which validates the input text using the onValidation event. The problem I have is that when I have input...
5
by: Micky | last post by:
VB v7.1.3088 NET v1.1.4322 SP1 My mate has a strange problem regarding the ESC key and validation. When he hits the Cancel button on his form, the form does not validate. This is correct...
1
by: HeavyD | last post by:
I have a form with numerous textboxes and I use the validating event to validate these items. If I want to close that form with the X button in the upper right corner of that window validation may...
3
by: guest | last post by:
I have a problem, I have Javascript that opens a popup. I want to avoide the user from closing the parent window first. I dont want to use showDialog, I want to use window.open() only.. Is there any...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.