BUG: GotFocus & Valid Events Fire Unexpectedly in Box of Grid (139913)
The information in this article applies to:
- Microsoft Visual FoxPro for Windows 3.0
- Microsoft Visual FoxPro for Windows 5.0
- Microsoft Visual FoxPro for Windows 5.0a
- Microsoft Visual FoxPro for Windows 6.0
This article was previously published under Q139913 SYMPTOMS
The GotFocus and Valid events of a text box in a grid column fire
unexpectedly if you set the focus to the text box from outside the grid.
The GotFocus event fires. Then the Valid event fires, and then the GotFocus
event fires again. Then focus finally settles on the control. This means
that any code in the GotFocus event executes twice, and the code in the
Valid event fires before the text box has been processed. In Visual FoxPro
5.0a, the GotFocus event fires twice but the Valid event does not fire.
WORKAROUND
Use public variables or custom properties of the form to test conditionally
whether the Valid and GotFocus events should fire. The following steps
provide an example.
Step-by-Step Example Workaround- Create a custom property called FiredFrom.
- Set the initial value of the FiredFrom property to "".
- Create another custom property called TimesThrough.
- Set the initial value of TimesThrough to 0.
- In the Click event of the command button that sets the focus to the text
box in the grid column, add the following line of code before the call
to the SetFocus method:
THISFORM.FiredFrom = 'CommandBtn'
- In the Valid event of the text box, add a conditional structure such as
this one:
IF THISFORM.FiredFrom = 'commandbtn'
THISFORM.FiredFrom = ""
ELSE
*do your code
ENDIF
- In the GotFocus event, add the following line of code as the first line:
THISFORM.TimesThrough = THISFORM.TimesThrough + 1
- Then add a conditional structure to the GotFocus event such as this one:
IF THISFORM.TimesThrough <= 1
*do your code
ELSE
THISFORM.TimesThrough = 0
ENDIF
STATUS
Microsoft has confirmed this to be a problem in the Microsoft products
listed at the beginning of this article. We are researching this problem
and will post new information here in the Microsoft Knowledge Base as it
becomes available.
Modification Type: | Major | Last Reviewed: | 10/16/2002 |
---|
Keywords: | kbBug kbProgramming KB139913 |
---|
|