7

The LA Fox Developer Newsletter
February 1998
Froms and Grids Revisited...
Yet Another Approach
to Forms and Grids
by Nick Neklioudov
[Ed. Note: Received this note/article in my e-mail box;
Here is the updated version of the article. Nick
So here is the revised article. Enjoy.]

I believe all of us are familiar with that set of four navigational buttons “First”, “Prior”, “Next”, Last” we use for data entry or maintenance forms. You need to put some code in their Click() events, enable or disable navigation buttons, according to the position of record pointer in a table. Of course, usually all we do it only once, and save this commandgroup as a class for reuse. I would like to suggest another approach for VFP 5.0 which eliminates the need in that commandgroup at all.

Everybody knows, that we can put any control into a grid cell, but maybe not everybody realizes that it is possible to put there also any container, even the whole form, which gives us some extra opportunities.

I created this sample after discussion about “Scrolling grid” in the thread, started by Jon Pasketton UT in January 1997.


This example contains a pageframe, placed into a grid cell instead of default textbox. The pageframe contains 3 pages with all necessary controls and should be saved as class in a class library.

Say, we use EMPLOYEE.DBF from Tasmanian Traders sample as our data source. Our pageframe has Height = 300 and Width = 400 , so we create a form, with a grid of 1 column, then drop
our new pageframe class into grid’s column, set CurrentControl for the Columni to the pageframe and remove default textbox. Also we have to make sure that grid properties are set to:

ColumnCount = I
DeleteMark = .F.
GridLines = 0
HeaderHeight = 0
Height = 300
HighlightRow = .F.
RecordMark = .F.
RecordSource “employee”
RowHeight = 300
ScroliBars = 2
Width = 400
Columnl.Width = 400
Columnl.Sparse = .F.

The trick is that now the grid cell has the exact size of the pageframe (or any other container you are using).

After those settings we run our form and see the pageframe, which has a vertical scrollbar on the right side. We can use this scrollbar to navigate through our data source like we do it with a text in MS Word. Note, that the record shown in the pageframe is not the current record in our data source until we actua’ly click anywhere on the pageframe or any of its controls. Only after that record pointer actually moves. If you want to move the record pointer according to shown record, you may use Grid.MouseDown and MouseUp events for that:
Grid.MouseDown
LPARAMETE~S nButton nShft, nXCoGrd, nyCoord
*
next two lines are here to prevent appearing
*
error messages 109 or 130
*
which Is happening If the focus inside a container
*
prevlousely was in the Editbox bound to Memo field.
thisform.anyControlOutsideGrid.SetFocus()
this.SetFocus()

Grid.MouseUp
LPARAMETERS nButton, nShift, nXCoord, nYCoord thls.ActivateCell(1 ,1)
this.Columnl .cntMyContainer.myControl.SetFocus()  

So, now we have no need in any code we previously used in our navigational commandgroup.

This approach “as is” may be used for forms, which works directly with tables or views, and use APPEND BLANK for adding records, or, for any forms which are used just to represent data.

Sometimes, when you open this form in Form Designer again, after adding pageframe to the grid, it can give you an error message:

“Error loading file - record number X - Pageframel (or one of its members). Pageframe cannot be sized that small”

However, that pageframe instance in the grid column has size 300 x 400 pixels. I opened my form’s .SCX file by USE
(Con’t, page 8)
Page 7

7