How To Display Blank in Place of .NULL. in a Grid Column

Last reviewed: October 29, 1996
Article ID: Q157052
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b, 5.0

SUMMARY

This article describes how to display a blank in place of .NULL. in a Grid column in Visual FoxPro 3.0, and 3.0b.

MORE INFORMATION

By default, fields containing NULL values are displayed as .NULL. in a Grid in all versions of Visual FoxPro. To display a blank in place of .NULL. in a column of a grid in Visual FoxPro 3.0 and 3.0b, place an inline if (IIF) statement in the DynamicForeColor property of the subject column. The IIF sets the column's ForeColor to the same color as the Grid Column's BackColor when the field contains a value. In Visual FoxPro 5.0 a NULL value can be displayed as a blank in a Grid by issuing the following SET command, which makes setting the DynamicForeColor unnecessary:

   SET NULLDISPLAY TO ''

Use the following steps to set the DynamicForeColor property of a column to white when a field contains a NULL value and to black when the value is not NULL. This article assumes that the Grid column's BackColor property is white (255,255,255) and that the ForeColor property is black (0,0,0). This article also assumes a working knowledge of creating forms, grids, and tables.

  1. Create a table called Test.dbf with a numeric field named nNulltest, which allows null values.

  2. Add some records to the table, storing .NULL. in the nNulltest field of some of the records.

  3. Create a form.

  4. Add a grid to the form.

  5. Add the table Test.dbf, created above, to the DataEnvironment of the form.

  6. Create a Grid on the form by dragging Test.dbf onto the form.

  7. Change the Grid's ColumnCount property to 1.

  8. Place the following in column 1's DynamicForeColor property:

          IIF(ISNULL(nNulltest),RGB(255,255,255),RGB(0,0,0))
    

    A true condition sets DynamicForeColor to white; a false condition is set to black.

  9. Run the form. Notice that a blank instead of .NULL. appears in the rows of the Grid pertaining to records with a NULL value in the nNulltest field. Should you get an error message starting with "Error loading file," you can correct the problem by deleting the = (equal sign) placed at the beginning of your IIF statement in the DynamicForeColor property.


KBCategory: kbprg kbhowto
KBSubcategory: FxprgGrid
Additional reference words: 3.00 3.00b 5.00 kbdsd vfoxwin



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: October 29, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.