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!

Change current rows back color

Status
Not open for further replies.

Brenton

Technical User
Jul 29, 2002
43
US
I need to change the current rows backcolor in my grid, but I only need to change 3 feilds backcolor not the whole row. Can someone help?
 
Brenton

Set the individual backcolor of the columns.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
How do I do this with just the current row?
 
this.SetAll("dynamicbackcolor", ;
"IIF(stock = 'B', RGB(255,0,0), RGB(0,0,0))", "Column")

in this case, i want to set the color red for anything tha says Stock = 'B'

yopu can have any criteria you wish..

like IIF(Product='Someproduct',rgb(),rgb())

Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
Brenton

What event should this go under?

TeknoSDS' suggestion, you would the code in the init of the grid, but I'm affraid that this will change the color of the whole row, but I noticed you said "but I only need to change 3 feilds backcolor not the whole row"

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
mgagnon-

I am still pretty confused. Lets go back to your original post.
This.SetAll("dynamicbackcolor",;
"iif((Stock='b', rgb(250,0,0), rgb(0,0,0))", "column

I just need to change 3 known columns. columns 1,6,and 8.
Can you explain your original post.

Sorry for all the questions. Foxpro is a bit new to me.
 
hOW BOUT THIS (int he Init event)
Only colum 1 and 3 for example.

this.Columns(1).dynamicbackcolor = "IIF(Stock = 'B', RGB(255,0,0), RGB(0,0,0))"

this.Columns(3).dynamicbackcolor = "IIF(Stock = 'B', RGB(255,0,0), RGB(0,0,0))"

Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
That would work, but I don't need an if condition. I just want the selected row to change the back color of columns 1, 6, and 8.

 
Brenton

just need to change 3 known columns. columns 1,6,and 8.
Can you explain your original post.


My original post was suggesting to change the column backcolor in design mode. In other word, all records in columns 1,6,and 8 would be a different color. But it seems you need to color them dynamically (in other words only color columns 1,6,and 8 if the condition is met), which isn't clear in your original post. I would suggest you try TeknoSDS' suggestion to see if it suits your needs.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi
I have two small procedures for this

The first (grid_hgl_prepare) is called in grid Init method
Code:
grid_hgl_prepare(this, RGB(0,0,0) , RGB(177,215,222),'Column1')

The second in grid AfterRowColChange event code
Code:
grid_hgl(this)

Code:
PROCEDURE grid_hgl_prepare
LPARAMETERS  toGridRef,tnSelForeColor,tnSelBackColor,tcPreservedColumns
*toGridRef			reference to grid object
*tnSelForeColor		selected row foreground color,integer ( ret by GetColor()) 
*tnSelBackColor		selected row background color,integer
*tcPreservedColumns columns that will not be changed
LOCAL lnForeColor,lnBackColor,i
toGridRef.addproperty('GridRecno',0)
lnForeColor = toGridRef.ForeColor
lnBackColor = toGridRef.BackColor
tcPreservedColumns = IIF(VARTYPE(tcPreservedColumns)#'C','',tcPreservedColumns)
FOR i=1 TO toGridRef.ColumnCount
	IF !toGridRef.Columns(i).name $ tcPreservedColumns
		toGridRef.Columns(i).DynamicBackColor = ;
			"iif(this.GridRecno = RECNO(),"+alltrim(str(tnSelBackColor))+","+alltrim(str(lnBackColor))+")"
		toGridRef.Columns(i).DynamicForeColor = ;
			"iif(this.GridRecno = RECNO(),"+alltrim(str(tnSelforeColor))+","+alltrim(str(lnForeColor))+")"
	ENDIF
ENDFOR

RETURN


PROCEDURE grid_hgl
LPARAMETERS toGridRef
*toGridRef	reference to grid object
IF RECNO()# toGridRef.GridRecno 
	toGridRef.GridRecno =  RECNO()
	toGridRef.Visible = .t.
ENDIF
RETURN
 
Thank you all...you've been a great help.

 
Brenton,
Try
this.Columns(1).dynamicbackcolor = "IIF(this.relativerow=this.relativerow, RGB(255,0,0), RGB(0,0,0))"

this.Columns(3).dynamicbackcolor = "IIF(this.relativerow=this.relativerow, RGB(255,0,0), RGB(0,0,0))"

and only the columns 1 and 3 of the CURRENT ROW will be changed

Regards,
Marcos
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top