The information in this article applies to:
- Microsoft Visual FoxPro for Windows, versions 3.0, 5.0, 5.0a
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.
MORE INFORMATION
Steps to Reproduce Problem
- Create a form, and place a grid on it.
- Set the Column Number to 2.
- Make the current control of the grid's second Column a text box.
- In the GotFocus event of the text box, enter the following line of
code:
WAIT WINDOW "GotFocus"
- In the Valid event of the text box, enter the following line of code:
WAIT WINDOW "Valid"
- Place a command button on the Form.
- In the command button's Click event, enter the following line of code:
THISFORM.Grid1.Column2.Text1.SetFocus
- Save and run the Form.
- 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, the GotFocus
event Wait Window appears twice.
Comparison Example
For comparison, follow these steps:
- Place a text box anywhere on the form.
- Put the same Wait Window statements in the new text box GotFocus and
Valid events.
- Place a second command button on the form.
- In the new command button's Click event, enter the following line of
code:
THISFORM.Text1.SetFocus
- Save and run the Form.
- 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.
|