PRB: Null Values Disappear When Selected in a Grid or Browse

Last reviewed: July 28, 1995
Article ID: Q132331
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0

SYMPTOMS

The text string ".NULL." for null values disappears when the field is selected. When you move out of the field, ".NULL." reappears. This is by design.

RESOLUTION

To display a text string ".NULL." for the currently selected field, create a column class that displays a label with the text string ".NULL." via the column's DynamicCurrentControl property. Copy the following code into TESTNULL.PRG, and then run it. You will see a grid with one column and 10 rows. Some of the rows contain numeric values, and some contain ".NULL." as a text string. Press DOWN ARROW to move through the records, note that the text string value of ".NULL." is displayed when the pointer is on a record that contains a null value.

  PUBLIC oForm
  oForm = CREATEOBJECT('myform')
  oForm.SHOW

  DEFINE CLASS mytextbox AS textbox
     SpecialEffect = 1
     BorderStyle = 0
     FontBold = .F.

     PROCEDURE keypress
     LPARAMETERS nKeyCode, nShiftAltCtrl

       IF nKeyCode = 48
         REPLACE testnull.name WITH .NULL.
         This.Value = ".NULL."
         NODEFAULT
       ENDIF
     ENDPROC
  ENDDEFINE

  DEFINE CLASS mytextbox1 AS mytextbox
     ControlSource = "testnull.name"
  ENDDEFINE

  DEFINE CLASS mytextbox2 AS mytextbox
     ControlSource = "This.Value"
     Value = ".NULL."

     PROCEDURE gotfocus
        This.Value = ".NULL."
     ENDPROC

     PROCEDURE lostfocus
        IF This.Value <> ".NULL."
           REPLACE testnull.name WITH This.Value
        ENDIF
     ENDPROC
  ENDDEFINE

  DEFINE CLASS mycolumn AS column
     DynamicCurrentControl = "IIF(ISNULL(testnull.name),'text2', 'text1')"
     Sparse = .f.
     Bound = .f.

     ADD OBJECT text1 AS mytextbox1
     ADD OBJECT text2 AS mytextbox2
  ENDDEFINE

  DEFINE CLASS mygrid AS grid
     RecordSource = ALIAS()
     ADD OBJECT c1 AS mycolumn
  ENDDEFINE

  DEFINE CLASS myform AS form
     ADD OBJECT g1 AS mygrid

     PROCEDURE load
        DELETE FILE testnull.dbf
        CREATE TABLE testnull (name c(10) NULL)

        FOR cnt = 1 to 10
          APPEND BLANK
          REPLACE name WITH IIF(MOD(RAND()*100, 2) >=1, SYS(3), .NULL.)
        ENDFOR
        GO TOP
     ENDPROC

     PROCEDURE unload
        CLOSE DATA ALL
     ENDPROC
  ENDDEFINE

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

To see the behavior described above, run the following code in the Command window:

   CREATE TABLE test (name C(10) NULL)
   APPEND BLANK
   REPLACE name WITH "Harry"
   APPEND BLANK
   REPLACE name WITH .NULL.
   BROWSE

The currently selected field has no text in it. Press the UP ARROW key or click in record 1. Record 2 now displays the ".NULL." text string.


Additional reference words: 3.00 VFoxWin browse
KBCategory: kbui kbprb
KBSubcategory: FxotherGeneral


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 28, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.