473,326 Members | 2,090 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,326 software developers and data experts.

Lost Focus

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
ng****@freeler.nl
Nov 15 '05 #1
6 28428
>>>>> "Patrick" == Patrick De Ridder <ng****@freeler.nl> writes:

Patrick> How do I connect to an event being thrown when a field has
Patrick> lost focus? Could you please give a code example?

WinForm or WebForm?

--
Peter Wu
Powered by Microsoft Windows XP [Version 5.1.2600]
Nov 15 '05 #2
mk
For a windows application:

[Assuming that you wish to receive LostFocus notification
for a textbox called textBox1]

Create a method as follows:

private void textBox1_LostFocus(object sender,
System.EventArgs e)

Add the following to InitializeComponent():

this.textBox1.LostFocus += new System.EventHandler
(this.textBox1_LostFocus);

HTH,

mk

-----Original Message-----
How do I connect to an event being thrown when a field haslost focus? Could you please give a code example?
--
Patrick De Ridder
ng****@freeler.nl
.

Nov 15 '05 #3
Hi mk,

Your solution to signify the loss of focus of a text box works fine !
Many thanks.
--
Patrick De Ridder
ng****@freeler.nl
Nov 15 '05 #4
100 <10*@100.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
Hi Patric,

A bunch of events are fired when the control loses the focus.
The right order is:
Leave
Validating
Validated
LostFocus

According to the event order above. You will receive LostFocus only if the
focus is actually lost and Leave as a inforamtion when request for changing the focus has arrived. Validating event handler can cancel the request and
it is posible to receive Leave, but not to receive LostFocus.

Anyway there is a bug in the framework and this order is valid only when the focus has been chaged using the TAB key to circle among the controls. If you use the mouse for changing the focus (which is most often used I think) the event order is:
LostFocus
Leave
Validating
Validated

You can see that you will receive LostFocus first and then the others
events. Validating event handler can cancel the operation and the focus
won't be changed even though you have received LostFocus.
So, the LostFocus is not reliable.
I haven't seen good workaround for this bug. Some people suggest catching
Windows messages, other using some special flags inside the form class. But I think there is no universal cure for this. Until MS don't fix this the
best workaround depends on the application logic.


Hi 100,

This is very interesting. However, what you
write is not totally within the scope of my
understanding at this point in time. Are
there any references for me to look at
on what you are discussing?

I have applied what mk advised me to do,
and that works fine.So I am very pleased.

Greetings,
--
Patrick De Ridder
bg****@freeler.nl
Nov 15 '05 #5
100
Hi Patric,
I have applied what mk advised me to do,
and that works fine.So I am very pleased.

This is the right way to do it. I just warned you about a well known bug in
the framework.
As long you don't do any validation of the data typed in text boxes It will
be fine. I just mantioned it just in case you are going to use validating
event. If you use LostFocus and Validating event together you will
definitely run into this.

B\rgds
100

Nov 15 '05 #6
On Mon, 11 Aug 2003 20:39:55 +0200, "Patrick De Ridder"
I will read up on validation, since that appears to be your main concern,
and I will have been warned by you not to combine it with the focus stuff.
Actually I do quite a bit of data validation (my code) in the prig, alerting
the user in the case of incorrect prig use with message boxes. Should I
understand from you that there are better alternatives to this approach?

Sorry prig = prog(gram)
(Typo)
--
Patrick De Ridder
ng****@freeler.nl

Nov 15 '05 #7

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

Similar topics

0
by: thomaz | last post by:
I use the DataSource like below to fill a Combobox: comboBox1.DataSource = dataSet1.Tables; comboBox1.DisplayMember = "ProductName"; When the user types any keyboard key i use the DROPDOWN...
3
by: Tom | last post by:
I have a VB .NET application that has a text box with the following code to handle the leave event. Private Sub txtIDiscountRate_TextChanged(ByVal sender As System.Object, ByVal e As...
6
by: Ellis Yu | last post by:
Hi all, I've a form containing some textbox fields. I wrote a simple code to check if the field is blank in lost focus event, an msg box will be shown to remind user about it. But don't why the...
0
by: Nick | last post by:
I have a situation wherein i have a text box, that has abc() being executed whenever the lost focus event is triggered. However, there is an exceptional case where, if a button click causes the...
3
by: Greg | last post by:
My problem is that values in the bool column of a datagrid are only being updated to the database once the focus of the bool cell is lost. This is completely counter-intuitative. When a user clicks...
0
by: =?Utf-8?B?Qw==?= | last post by:
Hi, I have a series of textboxes on an aspx page. These textboxes are within an UpdatePanel. On the OnTextChanged Event of each textbox I do some calculations in my codebehind and update...
1
by: =?Utf-8?B?amFtZXNAbm9zcGFtLmNvbQ==?= | last post by:
When processing the OnGotFocus event, I need to know the window/control that lost the focus. Is there a way to determint this? With MFC, you could use OnSetFocus which passed you the window that...
1
by: ravikumar2007 | last post by:
I am working with .NET 3.5 framework within an WPF application. I have a windows application where for a textbox, I have defined the lost focus event. I need to call the Focus() method of any other...
3
by: muddasirmunir | last post by:
I am using the following code at mouse move event of label Now i want that when user lost focus from the label its color aging change back , on what event i want to do this code as there is no...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.