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

Textbox LostFocus event fires after Command Button's OnClick event

WINDOWS FORMS

I've a form that has a textbox that allows the user to enter a string.
On the LostFocus event, the textbox formats the string into a preferred
format.

However, if the user presses the "Save" button while the textbox has
the focus, the LostFocus code doesn't run at the right time, so that
the "Save" function is dealing with an incorrectly formatted string and
the whole caboodle goes splat.

I like the LostFocus event, because I've got upwards of 14 such
textboxes on various tabs on the form, which all may contain different
strings but must all be formatted in the correct format. Here is the
function that handles this:

Private Sub txtTimeStartAndEndArbitrated(ByVal sender As Object,
ByVal e As System.EventArgs) Handles txtMonStartArbitrated.LostFocus,
txtMonEndArbitrated.LostFocus, _
txtTueStartArbitrated.LostFocus, txtTueEndArbitrated.LostFocus, _
txtWedStartArbitrated.LostFocus, txtWedEndArbitrated.LostFocus, _
txtThurStartArbitrated.LostFocus, txtThurEndArbitrated.LostFocus,
_
txtFriStartArbitrated.LostFocus, txtFriEndArbitrated.LostFocus, _
txtSatStartArbitrated.LostFocus, txtSatEndArbitrated.LostFocus, _
txtSunStartArbitrated.LostFocus, txtSunEndArbitrated.LostFocus

Dim txtTextBox As TextBox = CType(sender, TextBox)

txtTextBox.Text = FormatArbTime(txtTextBox.Text)

End Sub

Any thoughts?

Edward

Aug 7 '06 #1
14 14551
Edward,

Why don't you set the enabled property to false on the save button and on
the lostfocus event, enable the save button, and on the gotfocus of each
textbox, set the enabled on the save button to false, until the textbox(es)
are populated?
--
Michael Bragg, President
eSolTec, Inc.
a 501(C)(3) organization
MS Authorized MAR
looking for used laptops for developmentally disabled.
"te********@hotmail.com" wrote:
WINDOWS FORMS

I've a form that has a textbox that allows the user to enter a string.
On the LostFocus event, the textbox formats the string into a preferred
format.

However, if the user presses the "Save" button while the textbox has
the focus, the LostFocus code doesn't run at the right time, so that
the "Save" function is dealing with an incorrectly formatted string and
the whole caboodle goes splat.

I like the LostFocus event, because I've got upwards of 14 such
textboxes on various tabs on the form, which all may contain different
strings but must all be formatted in the correct format. Here is the
function that handles this:

Private Sub txtTimeStartAndEndArbitrated(ByVal sender As Object,
ByVal e As System.EventArgs) Handles txtMonStartArbitrated.LostFocus,
txtMonEndArbitrated.LostFocus, _
txtTueStartArbitrated.LostFocus, txtTueEndArbitrated.LostFocus, _
txtWedStartArbitrated.LostFocus, txtWedEndArbitrated.LostFocus, _
txtThurStartArbitrated.LostFocus, txtThurEndArbitrated.LostFocus,
_
txtFriStartArbitrated.LostFocus, txtFriEndArbitrated.LostFocus, _
txtSatStartArbitrated.LostFocus, txtSatEndArbitrated.LostFocus, _
txtSunStartArbitrated.LostFocus, txtSunEndArbitrated.LostFocus

Dim txtTextBox As TextBox = CType(sender, TextBox)

txtTextBox.Text = FormatArbTime(txtTextBox.Text)

End Sub

Any thoughts?

Edward

Aug 7 '06 #2
Try using the textbox's "Validating" event..that's what it is for and should
work.
--
Dennis in Houston
"eSolTec, Inc. 501(c)(3)" wrote:
Edward,

Why don't you set the enabled property to false on the save button and on
the lostfocus event, enable the save button, and on the gotfocus of each
textbox, set the enabled on the save button to false, until the textbox(es)
are populated?
--
Michael Bragg, President
eSolTec, Inc.
a 501(C)(3) organization
MS Authorized MAR
looking for used laptops for developmentally disabled.
"te********@hotmail.com" wrote:
WINDOWS FORMS

I've a form that has a textbox that allows the user to enter a string.
On the LostFocus event, the textbox formats the string into a preferred
format.

However, if the user presses the "Save" button while the textbox has
the focus, the LostFocus code doesn't run at the right time, so that
the "Save" function is dealing with an incorrectly formatted string and
the whole caboodle goes splat.

I like the LostFocus event, because I've got upwards of 14 such
textboxes on various tabs on the form, which all may contain different
strings but must all be formatted in the correct format. Here is the
function that handles this:

Private Sub txtTimeStartAndEndArbitrated(ByVal sender As Object,
ByVal e As System.EventArgs) Handles txtMonStartArbitrated.LostFocus,
txtMonEndArbitrated.LostFocus, _
txtTueStartArbitrated.LostFocus, txtTueEndArbitrated.LostFocus, _
txtWedStartArbitrated.LostFocus, txtWedEndArbitrated.LostFocus, _
txtThurStartArbitrated.LostFocus, txtThurEndArbitrated.LostFocus,
_
txtFriStartArbitrated.LostFocus, txtFriEndArbitrated.LostFocus, _
txtSatStartArbitrated.LostFocus, txtSatEndArbitrated.LostFocus, _
txtSunStartArbitrated.LostFocus, txtSunEndArbitrated.LostFocus

Dim txtTextBox As TextBox = CType(sender, TextBox)

txtTextBox.Text = FormatArbTime(txtTextBox.Text)

End Sub

Any thoughts?

Edward
Aug 7 '06 #3

te********@hotmail.com wrote:
[snip]

Thanks, guys, I'll give these a shot.

Edward

Aug 7 '06 #4
You can put a My.Application.DoEvents() call as the first statement in the
Buttons click event. The pending lost focus event will be fired and you can
then proceed with with the save logic.

--
Terry
"te********@hotmail.com" wrote:
WINDOWS FORMS

I've a form that has a textbox that allows the user to enter a string.
On the LostFocus event, the textbox formats the string into a preferred
format.

However, if the user presses the "Save" button while the textbox has
the focus, the LostFocus code doesn't run at the right time, so that
the "Save" function is dealing with an incorrectly formatted string and
the whole caboodle goes splat.

I like the LostFocus event, because I've got upwards of 14 such
textboxes on various tabs on the form, which all may contain different
strings but must all be formatted in the correct format. Here is the
function that handles this:

Private Sub txtTimeStartAndEndArbitrated(ByVal sender As Object,
ByVal e As System.EventArgs) Handles txtMonStartArbitrated.LostFocus,
txtMonEndArbitrated.LostFocus, _
txtTueStartArbitrated.LostFocus, txtTueEndArbitrated.LostFocus, _
txtWedStartArbitrated.LostFocus, txtWedEndArbitrated.LostFocus, _
txtThurStartArbitrated.LostFocus, txtThurEndArbitrated.LostFocus,
_
txtFriStartArbitrated.LostFocus, txtFriEndArbitrated.LostFocus, _
txtSatStartArbitrated.LostFocus, txtSatEndArbitrated.LostFocus, _
txtSunStartArbitrated.LostFocus, txtSunEndArbitrated.LostFocus

Dim txtTextBox As TextBox = CType(sender, TextBox)

txtTextBox.Text = FormatArbTime(txtTextBox.Text)

End Sub

Any thoughts?

Edward

Aug 7 '06 #5

no no no.. bad Terry, bad.

-Boo
You can put a My.Application.DoEvents() call as the first statement in
the Buttons click event. The pending lost focus event will be fired
and you can then proceed with with the save logic.

"te********@hotmail.com" wrote:
>WINDOWS FORMS

I've a form that has a textbox that allows the user to enter a
string. On the LostFocus event, the textbox formats the string into a
preferred format.

However, if the user presses the "Save" button while the textbox has
the focus, the LostFocus code doesn't run at the right time, so that
the "Save" function is dealing with an incorrectly formatted string
and the whole caboodle goes splat.

I like the LostFocus event, because I've got upwards of 14 such
textboxes on various tabs on the form, which all may contain
different strings but must all be formatted in the correct format.
Here is the function that handles this:

Private Sub txtTimeStartAndEndArbitrated(ByVal sender As Object,
ByVal e As System.EventArgs) Handles txtMonStartArbitrated.LostFocus,
txtMonEndArbitrated.LostFocus, _
txtTueStartArbitrated.LostFocus, txtTueEndArbitrated.LostFocus, _
txtWedStartArbitrated.LostFocus, txtWedEndArbitrated.LostFocus, _
txtThurStartArbitrated.LostFocus, txtThurEndArbitrated.LostFocus,
_
txtFriStartArbitrated.LostFocus, txtFriEndArbitrated.LostFocus, _
txtSatStartArbitrated.LostFocus, txtSatEndArbitrated.LostFocus, _
txtSunStartArbitrated.LostFocus, txtSunEndArbitrated.LostFocus
Dim txtTextBox As TextBox = CType(sender, TextBox)

txtTextBox.Text = FormatArbTime(txtTextBox.Text)

End Sub

Any thoughts?

Edward

Aug 8 '06 #6

Terry wrote:
You can put a My.Application.DoEvents() call as the first statement in the
Buttons click event. The pending lost focus event will be fired and you can
then proceed with with the save logic.
Tried that - didn't work.

Edward

Aug 8 '06 #7

Dennis wrote:
Try using the textbox's "Validating" event..that's what it is for and should
work.
--
Dennis in Houston
Tried that - didn't work. The button's OnClick event still pre-empts
the textbox's Validating event.

Edward

Aug 8 '06 #8
Why?
--
Terry
"GhostInAK" wrote:
>
no no no.. bad Terry, bad.

-Boo
You can put a My.Application.DoEvents() call as the first statement in
the Buttons click event. The pending lost focus event will be fired
and you can then proceed with with the save logic.

"te********@hotmail.com" wrote:
WINDOWS FORMS

I've a form that has a textbox that allows the user to enter a
string. On the LostFocus event, the textbox formats the string into a
preferred format.

However, if the user presses the "Save" button while the textbox has
the focus, the LostFocus code doesn't run at the right time, so that
the "Save" function is dealing with an incorrectly formatted string
and the whole caboodle goes splat.

I like the LostFocus event, because I've got upwards of 14 such
textboxes on various tabs on the form, which all may contain
different strings but must all be formatted in the correct format.
Here is the function that handles this:

Private Sub txtTimeStartAndEndArbitrated(ByVal sender As Object,
ByVal e As System.EventArgs) Handles txtMonStartArbitrated.LostFocus,
txtMonEndArbitrated.LostFocus, _
txtTueStartArbitrated.LostFocus, txtTueEndArbitrated.LostFocus, _
txtWedStartArbitrated.LostFocus, txtWedEndArbitrated.LostFocus, _
txtThurStartArbitrated.LostFocus, txtThurEndArbitrated.LostFocus,
_
txtFriStartArbitrated.LostFocus, txtFriEndArbitrated.LostFocus, _
txtSatStartArbitrated.LostFocus, txtSatEndArbitrated.LostFocus, _
txtSunStartArbitrated.LostFocus, txtSunEndArbitrated.LostFocus
Dim txtTextBox As TextBox = CType(sender, TextBox)

txtTextBox.Text = FormatArbTime(txtTextBox.Text)

End Sub

Any thoughts?

Edward


Aug 8 '06 #9
Hmmmm,
Worked for me.
--
Terry
"te********@hotmail.com" wrote:
>
Terry wrote:
You can put a My.Application.DoEvents() call as the first statement in the
Buttons click event. The pending lost focus event will be fired and you can
then proceed with with the save logic.

Tried that - didn't work.

Edward

Aug 8 '06 #10
Hello Terry,

Because it's not guaranteed. The results will be unpredictable.

The proper method, and the mechanism provided to do exactly this, is to use
the validating event.

-Boo
Why?

"GhostInAK" wrote:
>no no no.. bad Terry, bad.

-Boo
>>You can put a My.Application.DoEvents() call as the first statement
in the Buttons click event. The pending lost focus event will be
fired and you can then proceed with with the save logic.

"te********@hotmail.com" wrote:

WINDOWS FORMS

I've a form that has a textbox that allows the user to enter a
string. On the LostFocus event, the textbox formats the string into
a preferred format.

However, if the user presses the "Save" button while the textbox
has the focus, the LostFocus code doesn't run at the right time, so
that the "Save" function is dealing with an incorrectly formatted
string and the whole caboodle goes splat.

I like the LostFocus event, because I've got upwards of 14 such
textboxes on various tabs on the form, which all may contain
different strings but must all be formatted in the correct format.
Here is the function that handles this:

Private Sub txtTimeStartAndEndArbitrated(ByVal sender As Object,
ByVal e As System.EventArgs) Handles
txtMonStartArbitrated.LostFocus,
txtMonEndArbitrated.LostFocus, _
txtTueStartArbitrated.LostFocus, txtTueEndArbitrated.LostFocus, _
txtWedStartArbitrated.LostFocus, txtWedEndArbitrated.LostFocus, _
txtThurStartArbitrated.LostFocus, txtThurEndArbitrated.LostFocus,
_
txtFriStartArbitrated.LostFocus, txtFriEndArbitrated.LostFocus, _
txtSatStartArbitrated.LostFocus, txtSatEndArbitrated.LostFocus, _
txtSunStartArbitrated.LostFocus, txtSunEndArbitrated.LostFocus
Dim txtTextBox As TextBox = CType(sender, TextBox)
txtTextBox.Text = FormatArbTime(txtTextBox.Text)

End Sub

Any thoughts?

Edward

Aug 8 '06 #11
Hi Ghost,
Had never heard that (unpredictable) before - is this something
relevent to VS2005? Is it considered a bug? It seems to me that any
language construct that produces 'unpredicable' results should be considered
a bug.
I realize that the validating event is MS's prefered way to do this, the
problem is that there are bugs in this method such as using an escape key to
click the cancel button - does not work properly. Basically, my experience
is that using the validating event really only works if you are willing to
postpone all validation until the user presses the "ok' or 'Save' button. If
you want to validate as the user moves from control to control - the
validating event is a nightmare. Of course, I am no expert and if you have
some knowledge to the contrary or know of some trick, I am all ears!
--
Terry
"GhostInAK" wrote:
Hello Terry,

Because it's not guaranteed. The results will be unpredictable.

The proper method, and the mechanism provided to do exactly this, is to use
the validating event.

-Boo
Why?

"GhostInAK" wrote:
no no no.. bad Terry, bad.

-Boo

You can put a My.Application.DoEvents() call as the first statement
in the Buttons click event. The pending lost focus event will be
fired and you can then proceed with with the save logic.

"te********@hotmail.com" wrote:

WINDOWS FORMS

I've a form that has a textbox that allows the user to enter a
string. On the LostFocus event, the textbox formats the string into
a preferred format.

However, if the user presses the "Save" button while the textbox
has the focus, the LostFocus code doesn't run at the right time, so
that the "Save" function is dealing with an incorrectly formatted
string and the whole caboodle goes splat.

I like the LostFocus event, because I've got upwards of 14 such
textboxes on various tabs on the form, which all may contain
different strings but must all be formatted in the correct format.
Here is the function that handles this:

Private Sub txtTimeStartAndEndArbitrated(ByVal sender As Object,
ByVal e As System.EventArgs) Handles
txtMonStartArbitrated.LostFocus,
txtMonEndArbitrated.LostFocus, _
txtTueStartArbitrated.LostFocus, txtTueEndArbitrated.LostFocus, _
txtWedStartArbitrated.LostFocus, txtWedEndArbitrated.LostFocus, _
txtThurStartArbitrated.LostFocus, txtThurEndArbitrated.LostFocus,
_
txtFriStartArbitrated.LostFocus, txtFriEndArbitrated.LostFocus, _
txtSatStartArbitrated.LostFocus, txtSatEndArbitrated.LostFocus, _
txtSunStartArbitrated.LostFocus, txtSunEndArbitrated.LostFocus
Dim txtTextBox As TextBox = CType(sender, TextBox)
txtTextBox.Text = FormatArbTime(txtTextBox.Text)

End Sub

Any thoughts?

Edward


Aug 8 '06 #12
Hello Terry,

It's not a bug or something 05-specific. You are attempting to control the
flow of events by massaging the message pump. By it's very nature this is
unpredictable. Any results you have which conform to your expectations are
purely coincidental and not by design.

On an architectural note.. I've always found the overhead of doing field
validation as the user inputs or immediately after they input to be a higher
cost than it's really worth. The ROI just isn't there. It's much easier
to fix any issues with the escape key/cancel button than it is to invent
a whole new validation scheme.

On a usability note, I absolutely hate using programs that force me to fix
input errors as I make them.. 95% of the time I dont make input errors..
and when I do it completely breaks my train of thought to have to stop, fix
something, and then move on. I'd rather get a summary of errors when Im
finished and have pressed the OK button.

-Boo
Hi Ghost,
Had never heard that (unpredictable) before - is this something
relevent to VS2005? Is it considered a bug? It seems to me that any
language construct that produces 'unpredicable' results should be
considered
a bug.
I realize that the validating event is MS's prefered way to do this,
the
problem is that there are bugs in this method such as using an escape
key to
click the cancel button - does not work properly. Basically, my
experience
is that using the validating event really only works if you are
willing to
postpone all validation until the user presses the "ok' or 'Save'
button. If
you want to validate as the user moves from control to control - the
validating event is a nightmare. Of course, I am no expert and if you
have
some knowledge to the contrary or know of some trick, I am all ears!
"GhostInAK" wrote:
>Hello Terry,

Because it's not guaranteed. The results will be unpredictable.

The proper method, and the mechanism provided to do exactly this, is
to use the validating event.

-Boo
>>Why?

"GhostInAK" wrote:

no no no.. bad Terry, bad.

-Boo

You can put a My.Application.DoEvents() call as the first
statement in the Buttons click event. The pending lost focus
event will be fired and you can then proceed with with the save
logic.
>
"te********@hotmail.com" wrote:
>
>WINDOWS FORMS
>>
>I've a form that has a textbox that allows the user to enter a
>string. On the LostFocus event, the textbox formats the string
>into a preferred format.
>>
>However, if the user presses the "Save" button while the textbox
>has the focus, the LostFocus code doesn't run at the right time,
>so that the "Save" function is dealing with an incorrectly
>formatted string and the whole caboodle goes splat.
>>
>I like the LostFocus event, because I've got upwards of 14 such
>textboxes on various tabs on the form, which all may contain
>different strings but must all be formatted in the correct
>format. Here is the function that handles this:
>>
>Private Sub txtTimeStartAndEndArbitrated(ByVal sender As Object,
>ByVal e As System.EventArgs) Handles
>txtMonStartArbitrated.LostFocus,
>txtMonEndArbitrated.LostFocus, _
>txtTueStartArbitrated.LostFocus, txtTueEndArbitrated.LostFocus, _
>txtWedStartArbitrated.LostFocus, txtWedEndArbitrated.LostFocus, _
>txtThurStartArbitrated.LostFocus, txtThurEndArbitrated.LostFocus,
>_
>txtFriStartArbitrated.LostFocus, txtFriEndArbitrated.LostFocus, _
>txtSatStartArbitrated.LostFocus, txtSatEndArbitrated.LostFocus, _
>txtSunStartArbitrated.LostFocus, txtSunEndArbitrated.LostFocus
>Dim txtTextBox As TextBox = CType(sender, TextBox)
>txtTextBox.Text = FormatArbTime(txtTextBox.Text)
>End Sub
>>
>Any thoughts?
>>
>Edward
>>

Aug 9 '06 #13
Hi Ghost,
Thanks for the input. I agree with you on *most* situations where the
user is entering data on a form. Validation can/should wait till the user
indicates that they are done. But, in some cases it can not. The kind of
apps that I work on most of the time fall into this catqagory. Often things
are changing with every keystroke (which is easier to handle) and whenever
the user navigates on the screen. I have never understood why a buttons
click event fires before the active control's lostfocus event, but it does
and going back to VB3, I have used the DoEvents call to handle any pending
lostfocus event. This has worked through VB6. I have not ported anything
to VB 2005 yet and based on what you are telling me, maybe I need to
reconsider how I do this.
Thanks again for taking the time,
--
Terry
"GhostInAK" wrote:
Hello Terry,

It's not a bug or something 05-specific. You are attempting to control the
flow of events by massaging the message pump. By it's very nature this is
unpredictable. Any results you have which conform to your expectations are
purely coincidental and not by design.

On an architectural note.. I've always found the overhead of doing field
validation as the user inputs or immediately after they input to be a higher
cost than it's really worth. The ROI just isn't there. It's much easier
to fix any issues with the escape key/cancel button than it is to invent
a whole new validation scheme.

On a usability note, I absolutely hate using programs that force me to fix
input errors as I make them.. 95% of the time I dont make input errors..
and when I do it completely breaks my train of thought to have to stop, fix
something, and then move on. I'd rather get a summary of errors when Im
finished and have pressed the OK button.

-Boo
Hi Ghost,
Had never heard that (unpredictable) before - is this something
relevent to VS2005? Is it considered a bug? It seems to me that any
language construct that produces 'unpredicable' results should be
considered
a bug.
I realize that the validating event is MS's prefered way to do this,
the
problem is that there are bugs in this method such as using an escape
key to
click the cancel button - does not work properly. Basically, my
experience
is that using the validating event really only works if you are
willing to
postpone all validation until the user presses the "ok' or 'Save'
button. If
you want to validate as the user moves from control to control - the
validating event is a nightmare. Of course, I am no expert and if you
have
some knowledge to the contrary or know of some trick, I am all ears!
"GhostInAK" wrote:
Hello Terry,

Because it's not guaranteed. The results will be unpredictable.

The proper method, and the mechanism provided to do exactly this, is
to use the validating event.

-Boo

Why?

"GhostInAK" wrote:

no no no.. bad Terry, bad.

-Boo

You can put a My.Application.DoEvents() call as the first
statement in the Buttons click event. The pending lost focus
event will be fired and you can then proceed with with the save
logic.

"te********@hotmail.com" wrote:

WINDOWS FORMS
>
I've a form that has a textbox that allows the user to enter a
string. On the LostFocus event, the textbox formats the string
into a preferred format.
>
However, if the user presses the "Save" button while the textbox
has the focus, the LostFocus code doesn't run at the right time,
so that the "Save" function is dealing with an incorrectly
formatted string and the whole caboodle goes splat.
>
I like the LostFocus event, because I've got upwards of 14 such
textboxes on various tabs on the form, which all may contain
different strings but must all be formatted in the correct
format. Here is the function that handles this:
>
Private Sub txtTimeStartAndEndArbitrated(ByVal sender As Object,
ByVal e As System.EventArgs) Handles
txtMonStartArbitrated.LostFocus,
txtMonEndArbitrated.LostFocus, _
txtTueStartArbitrated.LostFocus, txtTueEndArbitrated.LostFocus, _
txtWedStartArbitrated.LostFocus, txtWedEndArbitrated.LostFocus, _
txtThurStartArbitrated.LostFocus, txtThurEndArbitrated.LostFocus,
_
txtFriStartArbitrated.LostFocus, txtFriEndArbitrated.LostFocus, _
txtSatStartArbitrated.LostFocus, txtSatEndArbitrated.LostFocus, _
txtSunStartArbitrated.LostFocus, txtSunEndArbitrated.LostFocus
Dim txtTextBox As TextBox = CType(sender, TextBox)
txtTextBox.Text = FormatArbTime(txtTextBox.Text)
End Sub
>
Any thoughts?
>
Edward
>


Aug 9 '06 #14
Edward,
- What does your OnClick event look like?

Are you overriding the OnClick method or are you handling the Click event
itself?

If you are overriding the OnClick method are you calling the MyBase.OnClick
first, last or not calling it?

- Which version of .NET?

Using code similar in .NET 2.0 (VS 2005) to:

Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.LostFocus
Debug.WriteLine("TextBox1_LostFocus", Application.ProductName)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Debug.WriteLine("Button1_Click", Application.ProductName)
End Sub

I am not able to reproduce the problem.
Using a custom button similar to:

Public Class Button
Inherits System.Windows.Forms.Button

Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
Debug.WriteLine("OnClick", Application.ProductName)
MyBase.OnClick(e)
End Sub

End Class

I am not able to reproduce the problem (again in .NET 2.0).

- Which OS?

The above were tested on Windows XP Pro 32bit.

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
<te********@hotmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
| WINDOWS FORMS
|
| I've a form that has a textbox that allows the user to enter a string.
| On the LostFocus event, the textbox formats the string into a preferred
| format.
|
| However, if the user presses the "Save" button while the textbox has
| the focus, the LostFocus code doesn't run at the right time, so that
| the "Save" function is dealing with an incorrectly formatted string and
| the whole caboodle goes splat.
|
| I like the LostFocus event, because I've got upwards of 14 such
| textboxes on various tabs on the form, which all may contain different
| strings but must all be formatted in the correct format. Here is the
| function that handles this:
|
| Private Sub txtTimeStartAndEndArbitrated(ByVal sender As Object,
| ByVal e As System.EventArgs) Handles txtMonStartArbitrated.LostFocus,
| txtMonEndArbitrated.LostFocus, _
| txtTueStartArbitrated.LostFocus, txtTueEndArbitrated.LostFocus, _
| txtWedStartArbitrated.LostFocus, txtWedEndArbitrated.LostFocus, _
| txtThurStartArbitrated.LostFocus, txtThurEndArbitrated.LostFocus,
| _
| txtFriStartArbitrated.LostFocus, txtFriEndArbitrated.LostFocus, _
| txtSatStartArbitrated.LostFocus, txtSatEndArbitrated.LostFocus, _
| txtSunStartArbitrated.LostFocus, txtSunEndArbitrated.LostFocus
|
| Dim txtTextBox As TextBox = CType(sender, TextBox)
|
| txtTextBox.Text = FormatArbTime(txtTextBox.Text)
|
| End Sub
|
| Any thoughts?
|
| Edward
|
Aug 10 '06 #15

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

Similar topics

4
by: MJW | last post by:
Is there a way for me to know if or which command button was just clicked that triggers the LostFocus event for the current control on a Form? I have a form that has many types of users who each...
0
by: Joachim | last post by:
I wonder if it is possible and if it is how it is done to trigger a right-click event performed on a command button in Visual C++ 6? The ClassWizard only gives two options: BN_CLICKED and...
2
by: Paul | last post by:
Just wondering how to close a window in vb.net? I have a close button and need this for the click event.
2
by: Rebecca | last post by:
I have a dynamically created command button on a .net page that adds 1 row to a sql server table when clicked. The page_load event load rows from that table for the user to view, but for some reason...
3
by: chris | last post by:
I have a form det-up as a continous form. In the Header of the form I have a command button called "Approve". What I'm looking to do is when the user clicks the command button all of the records...
1
by: adrianm4380 | last post by:
Is it possible to call the on click event procedure for a command button on a custom toolbar? I have a menu of buttons that open various forms in varying ways that are all controlled in the on...
2
by: Debbie | last post by:
I have always used VBScript but now need to convert my syntax to JavaScript. In an external file, I have a function that is called when a user clicks a button on a login page. The function checks...
1
by: chirag1989 | last post by:
Can some one just tell me out how can i use onclick event actual i m makin a library management system so i need to make a procedure that is called on clickin a button How To make procedure that...
12
by: Richard Penfold | last post by:
I have a form with a subform containing the combo box I want to update. I have a command button in the header of the main form that launches a report in print preview mode. I want to update the...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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
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...

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.