Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Filling grid completely
Message
 
 
To
14/09/2015 09:33:13
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01624580
Message ID:
01624585
Views:
69
>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	
>
Thank you very much. I will read your description here and in the book (I bought it but have not looked at it in a long time).
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform