Microsoft KB Archive/139913

= BUG: GotFocus & Valid Events Fire Unexpectedly in Box of Grid =

Article ID: 139913

Article Last Modified on 10/16/2002

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



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 </li>  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 </li></ol>

<div class="status_section">

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.

<div class="moreinformation_section">

Steps to Reproduce Problem
<ol> Create a form, and place a grid on it.</li> Set the Column Number to 2.</li> Make the current control of the grid's second Column a text box.</li>  In the GotFocus event of the text box, enter the following line of code: WAIT WINDOW "GotFocus" </li>  In the Valid event of the text box, enter the following line of code: WAIT WINDOW "Valid" </li> Place a command button on the Form.</li>  In the command button's Click event, enter the following line of code: THISFORM.Grid1.Column2.Text1.SetFocus </li> Save and run the Form.</li> Click the command button. The GotFocus event Wait Window appears. Then the Valid event Wait Window statement appears, and then the GotFocus event Wait Window appears again. In Visual FoxPro 5.0a and 6.0, the GotFocus event Wait Window appears twice.</li></ol>

Comparison Example
For comparison, follow these steps:

<ol> Place a text box anywhere on the form.</li> Put the same Wait Window statements in the new text box GotFocus and Valid events.</li> Place a second command button on the form.</li>  In the new command button's Click event, enter the following line of code: THISFORM.Text1.SetFocus </li> Save and run the Form.</li> <li>Click the second command button to set the focus to the text box on the form. In this case, you only see the GotFocus event Wait Window.</li></ol>

Additional query words: kbvfp500 kbvfp600

Keywords: kbbug kbprogramming KB139913

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.