RUN()

AllowAddNew

This property, added in VFP 5, gives you control over whether users can add new records to a grid by moving down out of the last item.

Usage

grdGrid.AllowAddNew = lLetUserAdd lLetUserAdd = grdGrid.AllowAddNew
A lot of users view a grid as being pretty much the same thing as a word processor table or a spreadsheet, and expect to be able to add new records on the fly by moving out of the last record. This property controls that ability. When AllowAddNew is .T., pressing the down arrow in any field of the last record in a grid adds a new record to the RecordSource of the grid.

We're glad they added this property, but there's still not enough control over this capability. As programmers, we want an event that fires when a new record is added this way, so we can respond appropriately. The feature our users want is the one that tables in Word have—when you tab out of the last item in table, a new row is added to the table. You can do this in VFP, but you have to write an awful lot of code to make it work.

You can add records to the grid's RecordSource programmatically (APPEND BLANK or INSERT INTO) regardless of the setting of this property. This just controls the grid's interface.

AllowAddNew respects a table's read-only status. However, when the table is read-only for any reason (the table's or the grid's ReadOnly property is set to .T., the table was explicitly opened read-only with USE NOUPDATE or was created by a SELECT without READWRITE), attempting to add a record by pressing the down arrow gives you the error message "Cannot update selected cursor." We think this is terrible behavior—the down-arrow press should be ignored, just as it would be if AllowAddNew were set to .F.


Example

* You might let the user know that she can * add records. IF This.AllowAddNew    * Make a label visible and set its caption    ThisForm.lblAddMsg.Caption = ;       "Add items by pressing down-arrow"    ThisForm.lblAddMsg.Visible = .T. ENDIF

See Also

Append, Insert-SQL, ReadOnly


View Updates

Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.



Hacker's Guide to Visual FoxPro 7. 0
Hackers Guide to Visual FoxPro 7.0
ISBN: 1930919220
EAN: 2147483647
Year: 2001
Pages: 899

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net