Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlighted record row in grid on return to form

Status
Not open for further replies.

keepingbusy

Programmer
Apr 9, 2000
1,470
GB

Hi all

I have a form with a grid that shows records from a table. In the grids init procedure is:
Code:
PUBLIC grno
grno = RECNO()
THIS.setall("Dynamicbackcolor", ;
  "IIF(RECNO()=grno,RGB(0,0,128),RGB(255,255,255))","Column") 
THIS.setall("DynamicForecolor", ;
  "IIF(RECNO()=grno,RGB(255,255,255),RGB(0,0,0))","Column")
In the grids AfterRowColChange procedure is:
Code:
LPARAMETERS nColIndex
grno = RECNO()
THISFORM.GRID1.REFRESH
There are no problems with the form but when it is used to update or view records, upon return to the form, the record that has been updated or viewed, appears at the top of the list.

My question is more of a cosmetic one in that, how do I get the form to show the selected record highlighted on the grid half way down the grid instead of at the top when it returns from being updated or viewed?

The grid displays about 28 records.

Is this possible?

Thank you guys

Lee
 

Strange. I have just created an executable and now the form is showing the highlighted record after update or view halfway down the grid as outlined above.

I'll run with this for now and see how it goes.

Lee
 
Lee,

I've often seen this behaviour, and find it very irritating. As you've discovered, it's not even consistent.

One solution might be to use the grid's RelativeRow property to determine the position of the highlight, and then use the DoScroll method to scroll the grid as appopriate.

Having said that, I wonder if you could avoid the issue in this case by using HighlightStyle to achieve your goal, rather than DynamicBackColor. That way, you wouldn't have to refresh the grid -- just set focus to it instead -- and so the problem shouldn't arise. Worth a try, perhaps.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 

Mike

As always, your suggestions are much appreciated. You mention:
One solution might be to use the grid's RelativeRow property to determine the position of the highlight, and then use the DoScroll method to scroll the grid as appopriate.
I've not come across this before but I will check out the help file and post back.

I'm thinking if there is a way to ensure the highlighted row is approximately half way down the grid everytime it returns from a view or update, then this would be more beneficial.

Thank you Mike

Lee
 
Having done some research on the above, I found a thread that Marcia had contributed to at: thread1254-1242065

She has posted some code:
Code:
WITH This
  *** Calculate the maximum number of rows in the grid
  lnMaxRows = INT( ( .Height - .HeaderHeight - ;
    IIF( INLIST( .ScrollBars, 1, 3 ),;
    SYSMETRIC( 8 ), 0 ) ) / .RowHeight )
ENDWITH
Where in the Grid's properties would this be shown and will it show the middle row highlighted in the grid?

I did mention earlier that the form was showing the highlghted record where it should be but this is now inconsistent when it returns to the form when most of the time, the selected record is shown at the top of the grid.

Thank you

Lee

Windows Vista
Visual FoxPro Versions 6 & 9
 
Lee,

Marcia's code won't tell you anything about which record is selected or which row is highlighted. It determines the actual number of rows visible at any one time, regardless of whether the rows currently contain data.

As for where it would be executed, I'd guess you could do it at Init time, since the number of rows doesn't depend on the data in any way. If the form is resizable (vertically), it should also be executed at resize time.

I still feel that the RelativeRow property would be useful to you. If, after updating the grid, RelativeRow is 1, you could DoScroll half the number of rows returned by Marcia's code. That would put the hightlight in the middle of the grid if the data extends that far, otherwise it will be somewhere between the first record and the middle.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Just one problem Mike, the grid's property RelativeRow is not available in the drop down list or in the properties menu list.

By the way, the version I am using is VFP6

Lee



Windows Vista
Visual FoxPro Versions 6 & 9
 
Lee,

I'm pretty sure RelativeRow was available in VFP 6.

It should appear in the property sheet, but will be non-editable because it has no meaning at design time. You would normally check its value from within your code.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike

I added the following to the init procedure of the form:
Code:
thisform.grid1.relativerow=1
This gave me an error message:

Program error: Property RELATIVEROW is read-only

Have I put this command in the right place?

I'm not going to lose any sleep over this as it is purely a cosmetic thing, trying to get the focused record showing halfway down the grid.

Lee


Windows Vista
Visual FoxPro Versions 6 & 9
 
Lee,

The error message is correct. You can't store a value in the RelativeRow. It doesn't matter where you put your code - the property is read-only.

My suggestion was that you write code that checks the RelativeRow's value, and then uses that to decide whether to scroll the grid in order to position the highlight where you want it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top