Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Filling grid completely
Message
De
14/09/2015 09:33:13
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01624580
Message ID:
01624583
Vues:
97
This message has been marked as the solution to the initial question of the thread.
I have a grid bound to a cursor. The grid has about 15 rows. The cursor - almost always has more rows (20+). Before displaying the form with this grid the record pointer is moved to the last one (GO BOTTOM). When the grid is displayed the last record of the cursor is displayed in the 1st row of the grid. The rest of the grid rows are empty. Therefore, user has to scroll down to fill out the grid. How can I (in code) make sure that the entire grid is filled with the cursor, before displaying the form?

From Chapter 6 of 1001 Things You Wanted to Know About Visual FoxPro

How do I display the last full page of a grid? (Example: EndOfGrid.scx)

Generally speaking, when a form containing a grid is instantiated, the first record displayed in the grid is the first record in its RecordSource. Obviously, if you have code in the grid's Init method that moves the record pointer, this is not going to be true. But there are situations in which you want to display a fully populated grid where the last available record is displayed as the last line of the grid. This can be done, but it is not a trivial exercise.
At first you may think "Oh, this is a piece of cake! All I have to do is something liked this:"
WITH This
  GO BOTTOM IN ( .RecordSource )
  SKIP - <Number of rows - 1> IN ( .RecordSource )	
  .SetFocus()
ENDWITH
But if you actually test this approach, you will quickly discover that it doesn't perform correctly. Even though the grid is positioned on the correct record, this record is in the middle of the page and you must use the PAGE DOWN key to see the last record. If this is a common requirement for your grids, this sample code in the Init() method of EndOfGrid.scx is generic and can easily be put in a custom method of your grid class:
LOCAL lnMaxRows, lnRecNo

*** Display the last page of the grid when the form instantiates
IF DODEFAULT()
	WITH Thisform.GrdCustomer
		*** Calculate the maximum number of rows per grid page
		lnMaxRows = INT( ( .Height - .HeaderHeight - ;
					  IIF( INLIST( .ScrollBars, 1, 3 ), SYSMETRIC( 8 ), 0 ) ) / .RowHeight )
		GO BOTTOM IN ( .RecordSource )
    lnRecNo = RECNO( .RecordSource )
		*** Go to the record that should be in the first row of the last page
		SKIP -( lnMaxRows - 1 ) IN ( .RecordSource )	
		.SetFocus()
    IF .RelativeRow < 1
  		*** Make sure it is the first relative row 
  		DO WHILE .RelativeRow # 1
  			.DoScroll( 0 )
  		ENDDO	
    ELSE
      DO WHILE .RelativeRow # 1
        .DoScroll( 1 )
      ENDDO  
    ENDIF 
    *!* Now go back to the last record in the grid
    GO lnRecNo IN ( .RecordSource )
    .SetFocus() 
	ENDWITH
ENDIF	
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform