473,503 Members | 6,587 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# How to turn of validation when closing window

3 New Member
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 not occur.
For example a user is filling in data and he inputs something incorrect in a field, but he then quickly wants to close the window by pushing X in the upper right corner.
At the moment validation goes off and show a dialogbox that incorrect data is enterred when I press X.
How can I turn validation off when pressing X, so that the window closes immediately without validation?
Mar 18 '07 #1
1 4509
SammyB
807 Recognized Expert Contributor
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 not occur.
For example a user is filling in data and he inputs something incorrect in a field, but he then quickly wants to close the window by pushing X in the upper right corner.
At the moment validation goes off and show a dialogbox that incorrect data is enterred when I press X.
How can I turn validation off when pressing X, so that the window closes immediately without validation?
My initial thought was to set a global variable in the FormClosing event, but even with Application.DoEvents, there doesn't seem to be any way to get the FormClosing to fire before the Validation exits. You could use the Leave event instead of the Validating event because it does not fire when X'ing the form.

However, I think that a design change would be better: Add an ErrorProvider "control" to your form and set/clear the ErrorProvider flag in the Validating and/or Change event. Also, in that event, check to make sure that there are no controls with Errors, and enable the OK button only when all errors have been cleared.

http://www.c-sharpcorner.com/UploadF...andCSharp.aspx gives an example of this. It makes your form look much more professional and auto-magically gives error message. It was a very nice NET addition. HTH --Sam
Mar 18 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
8677
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
8848
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
9760
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
4826
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
8794
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
2765
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...
2
2999
by: Tom | last post by:
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...
5
3799
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
2576
by: vsuser | last post by:
Hi, When the close button is pressed on a form (X in the upper right hand corner), any necessary validation occurs first. However, I do not want any validation to occur when exiting that way. ...
0
7193
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
7067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7316
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...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.