Inadvertently bypassing LostFocus event by using shortcut key combo to click another button 
Author Message
 Inadvertently bypassing LostFocus event by using shortcut key combo to click another button
I have a form with several TextBox controls each of which has its data
validated during its LostFocus event.  I then have a cmdCalculate button
whose Click event does a series of calculations using the presumably valid
data from the TextBoxes.

If an invalid entry is made in a box and the user then clicks cmdCalculate,
the box's LostFocus event still fires and the cmdCalculate_Click event
doesn't happen until the entry is corrected.  This is all as it should be.

The problem is that a user can use a shortcut key combination (alt-c) to
trigger cmdCalculate without the TextBox's LostFocus event occurring.  This
causes the calculation to proceed despite an invalid entry.  Now I could
easily resolve this problem by removing the shortcut key combination but is
there a more rational way?  Perhaps a way of "forcing" the LostFocus event
when using the shortcut key prior to triggering the cmdCalculate_Click
event?

Thanks,
John



Thu, 06 Nov 2003 14:32:30 GMT  
 Inadvertently bypassing LostFocus event by using shortcut key combo to click another button
Just a suggestion. Perhaps a central validation procedure for all of these
TextBoxes, that can be called from their LostFocus events, and from
cmdCalculate_Click before it does the calculations. If the validations are time-
consuming you could keep track of the validated status of each text box in their
Tag properties or something like that.
Quote:
-----Original Message-----

I have a form with several TextBox controls each of which has its data
validated during its LostFocus event.  I then have a cmdCalculate button
whose Click event does a series of calculations using the presumably valid
data from the TextBoxes.

If an invalid entry is made in a box and the user then clicks cmdCalculate,
the box's LostFocus event still fires and the cmdCalculate_Click event
doesn't happen until the entry is corrected.  This is all as it should be.

The problem is that a user can use a shortcut key combination (alt-c) to
trigger cmdCalculate without the TextBox's LostFocus event occurring.  This
causes the calculation to proceed despite an invalid entry.  Now I could
easily resolve this problem by removing the shortcut key combination but is
there a more rational way?  Perhaps a way of "forcing" the LostFocus event
when using the shortcut key prior to triggering the cmdCalculate_Click
event?

Thanks,
John

.



Fri, 07 Nov 2003 21:45:17 GMT  
 Inadvertently bypassing LostFocus event by using shortcut key combo to click another button
I haven't tried it, but put the validation code in the Validate event
instead of the LostFocus event.

In the Validate event if the data is not correct you just say:
        Cancel=True
and the focus won't leave that control.
It may work even when the user presses Atl C

Let me know if it works, k?

Ken

Quote:

> I have a form with several TextBox controls each of which has its data
> validated during its LostFocus event.  I then have a cmdCalculate button
> whose Click event does a series of calculations using the presumably valid
> data from the TextBoxes.

> If an invalid entry is made in a box and the user then clicks cmdCalculate,
> the box's LostFocus event still fires and the cmdCalculate_Click event
> doesn't happen until the entry is corrected.  This is all as it should be.

> The problem is that a user can use a shortcut key combination (alt-c) to
> trigger cmdCalculate without the TextBox's LostFocus event occurring.  This
> causes the calculation to proceed despite an invalid entry.  Now I could
> easily resolve this problem by removing the shortcut key combination but is
> there a more rational way?  Perhaps a way of "forcing" the LostFocus event
> when using the shortcut key prior to triggering the cmdCalculate_Click
> event?

> Thanks,
> John



Sat, 13 Dec 2003 05:10:05 GMT  
 Inadvertently bypassing LostFocus event by using shortcut key combo to click another button
I haven't tried it, but put the validation code in the Validate event
instead of the LostFocus event.

In the Validate event if the data is not correct you just say:
        Cancel=True
and the focus won't leave that control.
It may work even when the user presses Atl C

Let me know if it works, k?

Ken

Quote:

> I have a form with several TextBox controls each of which has its data
> validated during its LostFocus event.  I then have a cmdCalculate button
> whose Click event does a series of calculations using the presumably valid
> data from the TextBoxes.

> If an invalid entry is made in a box and the user then clicks cmdCalculate,
> the box's LostFocus event still fires and the cmdCalculate_Click event
> doesn't happen until the entry is corrected.  This is all as it should be.

> The problem is that a user can use a shortcut key combination (alt-c) to
> trigger cmdCalculate without the TextBox's LostFocus event occurring.  This
> causes the calculation to proceed despite an invalid entry.  Now I could
> easily resolve this problem by removing the shortcut key combination but is
> there a more rational way?  Perhaps a way of "forcing" the LostFocus event
> when using the shortcut key prior to triggering the cmdCalculate_Click
> event?

> Thanks,
> John



Sat, 13 Dec 2003 05:09:47 GMT  
 Inadvertently bypassing LostFocus event by using shortcut key combo to click another button
It's possible John has a problem merely with using the causesvalidation
property of the command button.

He doesn't mention what version of VB he's using, but if it's 6.0, he should
be using the causesvalidation property, set to true for the command button.
He doesn't specifically say that his validation code is in the lostfocus
event, but he does imply such.

I had a similar problem, but in my case I use a toolbar, which has no
causesvalidation property, and as such, no validation occurs.  To overcome
that, in the toolbar button's click event, I have to call a validatecontrols
method, which causes the last control which had focus to execute its
validate event.

Another solution is to enable/disable the command button based upon the
status of text boxes.  This is easier if the text boxes are a control array,
as you can then place the validation code in just one routine.  The only
problem with this method is that placing it in the lost focus event requires
the user to tab out of the last valid data required textbox before he can
click the command button or use the shortcut key.  The only way around that
is to place the validation code (for enabled/disable command button logic)
in the textbox's change event instead of lostfocus.

--
Bill Hileman
Programmer/Analyst, DASI



Quote:
> I haven't tried it, but put the validation code in the Validate event
> instead of the LostFocus event.

> In the Validate event if the data is not correct you just say:
> Cancel=True
> and the focus won't leave that control.
> It may work even when the user presses Atl C

> Let me know if it works, k?

> Ken


> > I have a form with several TextBox controls each of which has its data
> > validated during its LostFocus event.  I then have a cmdCalculate button
> > whose Click event does a series of calculations using the presumably
valid
> > data from the TextBoxes.

> > If an invalid entry is made in a box and the user then clicks
cmdCalculate,
> > the box's LostFocus event still fires and the cmdCalculate_Click event
> > doesn't happen until the entry is corrected.  This is all as it should
be.

> > The problem is that a user can use a shortcut key combination (alt-c) to
> > trigger cmdCalculate without the TextBox's LostFocus event occurring.
This
> > causes the calculation to proceed despite an invalid entry.  Now I could
> > easily resolve this problem by removing the shortcut key combination but
is
> > there a more rational way?  Perhaps a way of "forcing" the LostFocus
event
> > when using the shortcut key prior to triggering the cmdCalculate_Click
> > event?

> > Thanks,
> > John



Sat, 13 Dec 2003 20:45:10 GMT  
 Inadvertently bypassing LostFocus event by using shortcut key combo to click another button
Bill

I made up a project like John was talking about, and he is right.

I placed the code in the LostFocus event at it happens like he said.
Then I moved the code from the LostFocus event to the Validate event and
it worked like I said.

So if he just moves the code he will of fixed the problem.

I checked, and the Causes Validation for the Button is already set to
True.
But it doesn't matter if it is True or False as far as the LostFocus
event is concerned.  It only matters for the Validate event.

Ken

Quote:

> It's possible John has a problem merely with using the causesvalidation
> property of the command button.

> He doesn't mention what version of VB he's using, but if it's 6.0, he should
> be using the causesvalidation property, set to true for the command button.
> He doesn't specifically say that his validation code is in the lostfocus
> event, but he does imply such.

> I had a similar problem, but in my case I use a toolbar, which has no
> causesvalidation property, and as such, no validation occurs.  To overcome
> that, in the toolbar button's click event, I have to call a validatecontrols
> method, which causes the last control which had focus to execute its
> validate event.

> Another solution is to enable/disable the command button based upon the
> status of text boxes.  This is easier if the text boxes are a control array,
> as you can then place the validation code in just one routine.  The only
> problem with this method is that placing it in the lost focus event requires
> the user to tab out of the last valid data required textbox before he can
> click the command button or use the shortcut key.  The only way around that
> is to place the validation code (for enabled/disable command button logic)
> in the textbox's change event instead of lostfocus.

> --
> Bill Hileman
> Programmer/Analyst, DASI



> > I haven't tried it, but put the validation code in the Validate event
> > instead of the LostFocus event.

> > In the Validate event if the data is not correct you just say:
> > Cancel=True
> > and the focus won't leave that control.
> > It may work even when the user presses Atl C

> > Let me know if it works, k?

> > Ken


> > > I have a form with several TextBox controls each of which has its data
> > > validated during its LostFocus event.  I then have a cmdCalculate button
> > > whose Click event does a series of calculations using the presumably
> valid
> > > data from the TextBoxes.

> > > If an invalid entry is made in a box and the user then clicks
> cmdCalculate,
> > > the box's LostFocus event still fires and the cmdCalculate_Click event
> > > doesn't happen until the entry is corrected.  This is all as it should
> be.

> > > The problem is that a user can use a shortcut key combination (alt-c) to
> > > trigger cmdCalculate without the TextBox's LostFocus event occurring.
> This
> > > causes the calculation to proceed despite an invalid entry.  Now I could
> > > easily resolve this problem by removing the shortcut key combination but
> is
> > > there a more rational way?  Perhaps a way of "forcing" the LostFocus
> event
> > > when using the shortcut key prior to triggering the cmdCalculate_Click
> > > event?

> > > Thanks,
> > > John



Sat, 13 Dec 2003 09:47:16 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Using arrow keys in listview doesn't generate a click event

2. Bypass click event

3. Setting Combo box ListIndex initiates Combo box Click event

4. Clicking outside combobox trigger click event of the combo box

5. LostFocus key event

6. Default command buttons bypassing LostFocus

7. Clicking a button in another application (one without a shortcut key)

8. Bypass Key (Shift Key)

9. How to handle shortcut key events in MS Outlook 2002

10. Alt Key With Shortcut Fires Events in Different Order

11. Combo Box Click Event...

12. combo box Click event not firing

 

 
Powered by phpBB® Forum Software