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!

Grid rows alternating colors 1

Status
Not open for further replies.

shenlon

Programmer
Jul 9, 2003
47
0
0
US
Right now I have my grid setup so that the rows alternate colors based on recno. It works great, except for when I sort the table any other way than on the primary index. Is there any way I can get each row to alternate colors regardless of how the table is sorted?
 
Shenlon,

Use SELECT to a view with an ORDER BY clause instead of using the table directly.

Regards,

Mike
 
I can't seem to get your suggestion to work, no matter what syntax I try. I'm using VFP 6.0 if that makes any difference.

I made a view, included all of the fields from the table, and it displays fine in the grid, but the code won't work to change the sort order.
 
VFP6 hasn't the ORDER BY in views. Try this:

Set your Grid1.RecordSourceType to SQL
Set the default startup SQL in the RecordSource ie.
Code:
SELECT cName, cCity, cState from mydb.mytable ORDER BY cName

In the click event of the grid headers change the RecordType ie.
Code:
this.parent.parent.RecordSource = ;
    "SELECT cName, cCity, cState from mydb.mytable ORDER BY cName"

Second header:
Code:
this.parent.parent.RecordSource = ;
    "SELECT cName, cCity, cState from mydb.mytable ORDER BY cCity"

etc.

NOCONSOLE is supposed to eliminate the browse that pops up when you click a header. I also expected to need to refresh, but didn't. Otherwise I got it partially working with VFP6.

Regards,

Mike
 
To get alternating colored stripes in a grid, put this code in the grid's refresh event:
Code:
this.SetAll("DynamicBackColor", ;
   "IIF(MOD(this.ActiveRow,2)=0,RGB(255,255,255),RGB(0,255,255))","Column")  && Alternate white and cyan stripes
You might have to put the same code in other events too - sometimes my grids lose their colored stripes, but I've never gotten around to researching it.

I know this code works in VFP 7 & 8, and I think it works in VFP6, but I'm not entirely positive.

Mike Krausnick
Dublin, California
 
Oops, mydb.mytable should be mydb!mytable.

Actually I like mkrausnick's solution better. Have a star.

Regards,

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top