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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to relate & display active rows in 4 grids ?

Status
Not open for further replies.

wilfranz

Technical User
Oct 4, 2003
122
US
Hello friends,

Problem: How to maintain the same active row on 4 grids (1 each on 4 pages of a pageframe).

I have a 4-page Pageframe on a Form. Each page has a similar grid bound to the same table (TEMPDATA). Each page-grid displays a different set of fields from the table. When the active row is moved by the user, I need the active row to follow in each of the other 3 grids -- and it must also remain in the visible display of the other grids. To complicate matters one of the grids (#4) has rows of greater height than the others. I.e. whereas most of the grids display about 25 rows, grid #4 shows only about 8.

The highlighting of the active row is no problem using a custom property (nCurrentRecNo) and the SETALL() method. The problem is geting the active row to remain visible and (preferably) at the same position from page-grid to page-grid. Unfortunately the ActiveRow property is ReadOnly. So how can this be done?

TIA

 
Wilfranz,

If I've understood this right, you've already done everything necessary. The active row is no more or less than the row corresponding to the current record. Since all four grids are bound to the same table, they will all have the same current record, and therefore the same active row.

I suspect that the reason you are not seeing the highlight is simply that the grid does not have focus. Try putting THIS.MyGrid.SetFocus in the Activate event of each page.

Or, if you have VFP 8.0 or later, set the HighlightStyle property to 2 ("retain highlight when grid loses focus").

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Because you have used pageframes, this is not too hard, bar the 'different' grid!

In the AfterRowColChange method for each grid, put some code like this:

Code:
** for the first page
if thisform.pf1.activepage = 1
  thisform.pf1.page2.grid1.refresh
  thisform.pf1.page3.grid1.refresh
  thisform.pf1.page4.grid1.refresh
endif

You need to vary it like this for each grid...

Code:
** for the second page
if thisform.pf1.activepage = 2
  thisform.pf1.page1.grid1.refresh
  thisform.pf1.page3.grid1.refresh
  thisform.pf1.page4.grid1.refresh
endif

Then in the Activate method for each page of the page frame, use code like this:

Code:
** for the first page
thisform.pf1.page1.grid1.setfocus

And vary it again for each one...

Code:
** for the second page
thisform.pf1.page2.grid1.setfocus

This will update each grid as you move the pointer, get a bit messy when you scroll past the end of the fle on any grid - but not too shabby.

The 'different' grid is more problematic. Can you set the rows to be the same height, and only expand them if the user double clicks on an entry?




Regards

Griff
Keep [Smile]ing
 
Griff,

I agree with your general approach, but I wonder about putting the Refresh in the AfterRowColChange. Refreshes are usually slow, and the AfterRowColChange will be called frequently. Since the grids are on separate pages, it seems to me that, if you need to do a refresh, you should do it in the page's Activate.

What do you think?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Hi Mike,

You could be right, but wilfranz did say he wanted to synchronise not only the record, but the position on the grid. I think the only way to do that with any certainty is to refresh the 'hidden' grids... of course I could be talking rubbish because I didn't actually test it without the refresh, and I don't have time now!

And as I said before, when any grid scrolls past the eof, it will scroll up beyond what the others can achieve...

Regards

Griff
Keep [Smile]ing
 
Thanks for all the great input, guys.

Mike Lewis, you hit it on the head with your first suggestion. This alone provided the continuity of the highlight from page to page. And it required only the one line of SetFocus() in each Activate event to do it. It also is effective in keeping the active row always in the visble portion of the grid window, even for the one "different" grid of triple row height.

(I blush to confess that initally, when I found that the SetFocus() wasn't working as you suggested, it suddenly dawned on me that I actually was not using the same master table as RecordSource for all the grids. I was using an SQL derivative of the master table for each grid -- tempcsr1, tempcsr2, tempcsr3, etc. Duhhh! As soon as I corrected that, things fell into place.)

But trying to keep the record rows in identical alignment from page to page is proving elusive. I can walk around that problem, because it is not essential to the project. But I would like to solve it just for the principle of it.

Griff, are you suggesting (by your code example) that the Refresh will accomplish this (i.e. aligning the active records on each page)? Or should I be looking to use a RelativeRow, ActiveRow, and DoScroll method?

Many thanks again,

Bill
 
The refresh will (mostly) keep your rows in synch, except for your 'different' grid and if you scroll past the eof() on any grid - when it will pop up by one line.

Regards

Griff
Keep [Smile]ing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top