How to Append Records to a Grid
ID: Q138559
|
The information in this article applies to:
-
Microsoft Visual FoxPro for Windows, versions 3.0, 6.0
-
Microsoft Visual FoxPro for Macintosh, version 3.0b
SUMMARY
There are times when a user may want to append a record when they get to
the last record in a grid. This can be accomplished programmatically by
using the BeforeRowColChange and the AfterRowColChange events as shown by
example in this article.
MORE INFORMATION
One important piece of the example is setting the buffer mode of the form
to either optimistic or pessimistic. This allows the GETFLDSTATE() function
to perform correctly. In addition, this sample code uses no index order on
the data.
Step-by-Step Example
- Open the Forms Designer, and drop a grid on it.
- Create a new property of the form called nLastRec.
- In the Init event of the grid, place this code:
GO BOTTOM
ThisForm.nLastRec = RECNO()
GO TOP
- Place the following code in the BeforeRowColChange event.
LPARAMETERS nColIndex && This line is added automatically by FoxPro
&& nColIndex is current column the cursor is in
IF nColIndex = This.ColumnCount AND RECNO() = ThisForm.nLastRec ;
AND LASTKEY() = 9
APPEND BLANK
ThisForm.nLastRec = RECNO()
This.SetFocus
ENDIF
This code appends a record only if you press the TAB key to move through
the fields. Code would have to be added for conditionally appending
records based on different navigation through the fields.
- Place the following code in the AfterRowColChange event:
IF "3"$GETFLDSTATE(-1)
This.ActivateCell(This.ActiveRow, nColIndex)
ENDIF
- Add code similar to the following to commit the changes to the table.
This code can go into the Click event of a command button or in the
Destroy event of the form.
IF <condition to save>
=TableUpdate(.T.)
ELSE
=TableRevert(.T.)
ENDIF
Additional query words:
VFoxMac VFoxWin
Keywords : kbcode kbVFp300 kbVFp600 FxprgGrid
Version : 3.00 | 3.00b
Platform : MACINTOSH WINDOWS
Issue type :