473,698 Members | 2,242 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Suppress focus events of a textbox control in Validating event

Hello

I have a Data Entry Form having some controls including a TextBox. When the
user types an entry, I query a table and if it was entered before, I ask the
user (using ShowModal method of a custom message form) if he wants to see
his old entry in a new form. if he/she choose Yes, I create a new form and
show the previously entered data in it.

The problem is when I create and show the new form, the validating event is
fired two times and so it asks again if the user wants to see previously
entered data.
The application is an MDI application.

Please help me what am I wrong with.
Regards
Hamed
Jun 9 '07 #1
3 1971

"Hamed" <ha***@raymehr. comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Hello

I have a Data Entry Form having some controls including a TextBox. When
the user types an entry, I query a table and if it was entered before, I
ask the user (using ShowModal method of a custom message form) if he wants
to see his old entry in a new form. if he/she choose Yes, I create a new
form and show the previously entered data in it.

The problem is when I create and show the new form, the is fired two times
and so it asks again if the user wants to see previously entered data.
The application is an MDI application.

Please help me what am I wrong with.
Why don't you pass a local scope Boolean flag in the form's constructor, and
at the validating event check the flag, if the Boolean flag is true bypass
code/exit or else execute the code and exit?

Jun 9 '07 #2
The Validating event of the first form is fired twice not the second form.

I think there is some interference between focus events and ShowModal
method.

Please help. Am I wrong in using the Validating routines?

Hamed

Why don't you pass a local scope Boolean flag in the form's constructor,
and at the validating event check the flag, if the Boolean flag is true
bypass code/exit or else execute the code and exit?

Jun 9 '07 #3

"Hamed" <ha***@raymehr. comwrote in message
news:O$******** ******@TK2MSFTN GP02.phx.gbl...
The Validating event of the first form is fired twice not the second form.
Well, you should still be able to set some kind of flag there too. Maybe
some flag in a Global scope.

It's the same thing with having Textbox_Change event firer on a Form_load
where you have code in the TextBox_Change event, and you only want the code
in the event to executed when the user changes data in the Textbox.

You don't want the Textbox_Change event to firer on the Form_Load and
execute code because you populated default data in the TextBox.Text =
"MM/DD/YYYY", as an example for display purpose, which will make the
Textbox_Change event firer and code executed if you do bypass it during the
Form_Load.

You simply avoid the situation by setting a gbBoolen flag to true to make it
bypass the code in the Event and set it to false at the end of the Form_Load
to make the event execute the code when it's fired due to the user changing
data in the TextBox.

It's the same principles here. You know the conditions as to when this is
happening so set a Global Boolean flag, if you must, to true and bypass
code execution and set it to false when the method is exited.
Jun 9 '07 #4

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

Similar topics

6
28475
by: Patrick De Ridder | last post by:
How do I connect to an event being thrown when a field has lost focus? Could you please give a code example? -- Patrick De Ridder ngmail@freeler.nl
1
9295
by: seash | last post by:
Is there any way to suppress an event method? i got Enter & leave Events on two groupBoxs, they r " private void groupBox1_Enter(object sender, System.EventArgs e)" and private void groupBox1_Leave(object sender, System.EventArgs e) event methods, from msdn info the order of execution for them will be 1> Enter 2>GotFocus 3>lost focus 4>Leave 5>Validating i used only Enter and Leave events, after entering a groupBox i can see that...
0
5075
by: Miquel | last post by:
Hi all. I felt frustrated when developing an 'UserControl' derivated from textBox, because sequence event (and Validate event) seems to fail. I Always thought my code was wrong. But after trying the UserControl a lot of hours I have the feeling that c# (or .Net) fails. Thus, I have developed a simple program with 3 textBox, 1 Botton and 1 ListBox (for showing results) which fire OnEnter, OnGotFocus,
0
2463
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls which are not behaving as I would expect. Specifically, if there is a command button external to the usercontrol which is activated by a shortcut key (eg Alt-B), the command button Click event handler code 'executes' even though the textbox set...
10
3101
by: Dennis | last post by:
I have a simple form with one button and one text box. In the Form, I create an array list to track the events by adding a descriptive string item to the arraylist in each event. I first Click on the Button then Click on the TextBox and enter an "a" then click on the Button again. The following is what I get for the event tracking Arraylist: but - GotFocus but - Clicked but - LostFocus txt - Changed
7
1755
by: Bruce HS | last post by:
I'd like to call my ancestor Validation Function every time any control on a Win Form generates a Validating or Validated event. I'm using VB. I've extended Textbox, for instance, to have its events do this for me, but my extended textbox doesn't get created by those wonderful form setup wizards. So, 1) Is there a way I can pick up these events without having to code for each control and without using custom extended controls, OR
3
5406
by: Patrick [MSFT] | last post by:
Let me preface this with the goal I'm trying to achieve is mimic a feature of another language (Dexterity used by Microsoft Dynamics) and so while a filling a drop down list is a workable solution I'd rather do it like Microsoft Dynamics does and use separate textbox and lookup button. What I have is, simply, is a C# winform, a textbox and a pushbutton. On the textbox, on the validating event of the textbox I check my customer table...
3
1693
by: Hamed | last post by:
Hello I have a Data Entry Form having some controls including a TextBox. When the user types an entry, I query a table and if it was entered before, I ask the user (using ShowModal method of a custom message form) if he wants to see his old entry in a new form. if he/she choose Yes, I create a new form and show the previously entered data in it. The problem is when I create and show the new form, the validating event is fired two...
2
2475
by: Jonathan N. Little | last post by:
As part of a JavaScript precheck form validation I noticed a problem with trying to return focus to the field with an error. I have setup a demo page. http://www.littleworksstudio.com/temp/usenet/focus.html To simulate the problem, just enter or change the "first" textbox and either click or tab to another control., it is tied to the onchange event. An alert box that simulates the "warning". When you close it the focus will not move...
0
8676
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9164
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8898
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7734
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3051
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 we have to send another system
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.