Microsoft KB Archive/299528

= FIX: Focus Moves From Textbox In Grid Despite RETURN 0 In Valid Event =

Article ID: 299528

Article Last Modified on 10/16/2002

-

APPLIES TO


 * 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 Q299528



SYMPTOMS
RETURN 0 and NODEFAULT are often used to prevent default behavior in a control event. In Microsoft Visual FoxPro (VFP) 5.0 and 6.0, these commands do not prevent focus from leaving a text box in a grid column when they are used in the Valid event of the control.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in Microsoft Visual FoxPro version 7.0 for Windows.



Steps to Reproduce Behavior
  In VFP 5.0 or 6.0, paste the following code in a new project: *!* FIX: Q299528 Focus Moves From Textbox In Grid In Spite Of RETURN 0 In VALID CREATE CURSOR cur1 (f1 C(5), f2 i) INSERT INTO cur1 VALUES ('xxx',1) INSERT INTO cur1 VALUES ('yyy',2) GO TOP

PUBLIC oform1 oform1=CREATEOBJECT(&quot;form1x&quot;) oform1.SHOW RETURN

DEFINE CLASS form1x AS FORM AUTOCENTER = .T.   CAPTION = &quot;Form1&quot; NAME = &quot;Form1&quot;

ADD OBJECT grdcustomer AS GRID WITH ; COLUMNCOUNT = 2, ; LEFT = 12, ; RECORDSOURCE = &quot;cur1&quot;, ; RECORDSOURCETYPE = 1, ; TOP = 12, ; NAME = &quot;grdCustomer&quot;, ; Column1.CONTROLSOURCE = &quot;cur1.f1&quot;, ; Column1.NAME = &quot;Column1&quot;, ; Column2.CONTROLSOURCE = &quot;cur1.f2&quot;, ; Column2.NAME = &quot;Column2&quot;

ADD OBJECT text1 AS TEXTBOX WITH ; HEIGHT = 25, ; LEFT = 132, ; TOP = 220, ; WIDTH = 60, ; NAME = &quot;Text1&quot;

PROC INIT THISFORM.grdcustomer.Column1.REMOVEOBJECT('text1') THISFORM.grdcustomer.Column1.ADDOBJECT('text1','textboxx') THISFORM.grdcustomer.Column1.text1.VISIBLE = .T.   ENDPROC

PROCEDURE DESTROY USE IN cur1 ENDPROC ENDDEFINE

DEFINE CLASS textboxX AS TEXTBOX BORDERSTYLE = 0 MARGIN = 0 NAME = &quot;Text1&quot; PROCEDURE VALID IF !&quot;x&quot;$THIS.VALUE WAIT WINDOW 'Needs to have an &quot;x&quot;' TIME 1 RETURN 0 ENDIF ENDPROC ENDDEFINE  Save and run the code (the name is unimportant). A form with a grid and a text box is shown. Using the mouse, click in the second row of the grid, in the &quot;YYY&quot; text box. Left-click into the textbox at the bottom of the form.

At this point in the code, the Valid event of the text box in the grid displays a message box that says that a value of &quot;X&quot; is required. Note, however, that after the WAIT WINDOW clears, focus is now in the text box on the form, instead of in the text box in the grid. This occurs although the Valid event retuned 0, which should have prevented focus from leaving the grid text box.

If you run the same code in VFP 7.0 and follow the same steps, focus does not leave the grid text box.

NOTE: The LostFocus event of text boxes in a grid also has this problem. This was not fixed in VFP 7.0. It is advised that you use the Valid event to prevent focus from moving as detailed in the previous code.

Keywords: kbbug kbfix kboop kbcodesnippet kbvfp700fix KB299528

-

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

© Microsoft Corporation. All rights reserved.