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

Formatting grids 1

Status
Not open for further replies.
Yes.

IF (and only if) the underlying cursor or table is in natural order (no index in force) AND there are no deleted records AND there is no filter in force:

Use the column's DynamicBackColor property. Something like this (in the grid's Init):

Code:
THIS.Column1.DynamicBackColor = ;
  "IIF(MOD(RECNO("MyCursor"), 2) = 0, RGB(128, 128, 128), RGB(255, 255, 255))"

That will set alternate rows in the first column to white and grey (assuming MyCursor is the alias of the underlying cursor or table).

To highlight the entire row, either repeat the above for each column, or use the grid's SETALL() method (check the Help for details). You might also want to experiment with setting the ForeColor as well.

If the grid is not in natural order with no deleted records and no filter, it's a bit more complicated. In that case, you need to add a field to the cursor (I'll call it AltField in this example). Set it to .T in alternating records, and .F. in the others. Then do something like this:

Code:
THIS.Column1.DynamicBackColor = ;
  "IIF(MyCursor.AltField, RGB(128, 128, 128), RGB(255, 255, 255))"

In both cases, don't forget the double quotes around the entire IIF function, as shown above.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
By coincidence Mike, I have been playing around with some similar code I found and your explanation shows why it was not working. The table is indexed and is updated regularly.
I will give it a miss in this instance but I have noted it down for future reference - very useful especially on big tables.

Keith
 
To make a point clear: The almost-solution in thread184-1208158 is not working in the end, if you scroll back and forth. The best solution really is to have coloring data or at least a bool within the grid cursor and fill it with alternating values in sort order. Anyway no recordsoruce should have so much data in it, that it would take a lot of time to fill an additional field each time you sort.

Bye, Olaf.
 
> that will be mixed up in a table with deleted records
Put the other way around: Even a table in physical order will have problems with a solution based on recno() for the reason a deleted record causes a gap in the odd/even sequence, yes.

Bye, Olaf.
 
It always amazes me how many different ways there are to do a job in VFP.
I settled in the end for a bool column and it works a treat.
I did see those examples you suggested but they looked so complicated - I understand what they were about now.
Thanks

Keith
 
It always amazes me how many different ways there are to do a job in VFP.
I settled in the end for a bool column and it works a treat.
I did see those examples you suggested but they looked so complicated - I understand what they were about now.
Thanks

Keith
 
The final question is, if you really need alternating coloring. If you allow deleting or adding records, every add or delete needs a refill of the bool field to keep the alteranation working.
One other thing you could do is add a shape or container in front with a png with 100% and 90% transparency strips in the size of the grid rows. It just won't scroll in sync with the grid, but you could live with that, when records snap to the grid in the end.

It's much easier done in a report with a report variable toggeling betwen .t. and .f. and a light grey translucient shape with "print when" set to that bool report variable. You don't have that within the grid.

Bye, Olaf.
 
In the first place, yes, mike. But you may use the coordinate of clicks in a container or shape in conjunction with Gridhittest. Obviously it makes things even more complicated, if you need much interaction with the grid, but do you? More ideal would be something you could place behind the grid, but you can't make it transparent, AFAIK.

Another way to color rows would be using gdiplus and draw transparent rectangles, that don't mean a blocking object in front.

Bye, Olaf.
 
Good, that's the easy case. If you query into cursor and display the result for reading you can simply use the recno()%2 for even/odd numbers, because the query result a) has it's own record numbers b) has no deleted records and c) is in order of display.

If you talk about sortable readonly grid, you are already back with the problem, unless you sort by requerying with a different ORDER BY clause. But that's awful in performance with large data sets you retrieve. Nothing can beat the switch of sort order via SET ORDER with indexes on your data. Of course creating that indexes on a query result also takes it's time, but that might be okay to users as a start time of the form.

I just wanted to add all easy to overlook detail problems one might have with the alternating colored rows. Of course it's fine, if you have found a workable solution for your case, there's nothing wrong with that.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top