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

How to alternate row color in a view after changing order 1

Status
Not open for further replies.

bluesw3

Programmer
May 27, 2003
11
0
0
US
I have a view displayed on a grid which pulls records from 6 tables using UNION. Because union changes the order of my records I reset the order of the view. Im using recno to determine row color for most of my grids but it obviously wont work here. Are there any other ways to accomplish alternating row colors without having my records in their original order? Or is there a way to use union and keep my table records grouped properly?

Heres my union code:

CREATE SQL VIEW recrigo_view AS ;
SELECT * from recrigo_standardcargo WHERE recrigo_standardcargo.qty > 0 UNION ;
select * from recrigo_rentals WHERE recrigo_rentals.qty > 0 UNION ;
select * from recrigo_tubular WHERE recrigo_tubular.qty > 0 UNION ;
select * from recrigo_wellheads WHERE recrigo_wellheads.qty > 0 UNION ;
select * from recrigo_bits WHERE recrigo_bits.qty > 0 UNION ;
select * from recrigo_mud WHERE recrigo_mud.qty > 0

And my alternating color code:

This.Column1.DynamicBackColor = 'IIF(MOD(recno(), 2) = 0, RGB(230,250,240), RGB(255,255,255))'
 
Depending on your code, this will work..

This.Column1.DynamicBackColor = ;
'IIF(MOD(This.ActiveRow,2)=0, RGB(230,250,240), ;
RGB(255,255,255))'

OR you can make the entire row color..
MyGrid.Init
WITH THIS
.SetAll("DynamicBackColor", ;
"IIF(MOD(This.ActiveRow,2)=0, RGB(230,250,240), ;
RGB(255,255,255))","Column")
ENDWITH

Make sure that you suitably refresh() so that the colors are properly displayed. Otherwise, till the grid is focused, it will appear to have one color.

:)

____________________________________________
ramani - (Subramanian.G) :)
When you ask VFP questions, please add VFP version.
 
bluesw3,

I can't see why your existing method doesn't work.

You are creating a view which you are using as the RecordSource of the grid. Your DynamicBackColor is based on the record number of the view. I can't see how it makes any difference how you created the view. It is the RECNO() of the view which determines the background colour.

The only thing I can think of is that, at the time that the DynamicBackColor kicks in (that is, when the grid is refreshed), a different work area is selected. If that's the case, you can solve it by putting the view's alias in the RECNO() function:

This.Column1.DynamicBackColor = 'IIF(MOD(recno("recrigo_view"), 2) .. etc.

Might be worth a try.

Mike


Mike Lewis
Edinburgh, Scotland
 
Thanks ramani that worked great!
Mike, the reason I couldn't use my existing code was because my view has an order set to it which differs from recno()'s order. Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top