3.0 beta 2

Change cell color based on another column value

How can i change the bg or font color of a cell based on the values of another column. I have this but nothing happens:

var obj = new Active.Controls.Grid;
  obj.setDataText(function(i, j){return obj_data[i][j]});
  obj.setColumnText(function(i){return obj_columns[i]});

  obj.getColumnTemplate(0).setStyle("color", function(i,j){return obj_data[i][9]});
obj.setEvent("onmousewheel", onmousewheel);
var row = new Active.Templates.Row;
row.setStyle('background', alternate);
obj.setTemplate('row', row);

John Arthur
June 2,
Maybe like this:
function myColor(){
    var i = this.getRowProperty("index");
    return obj_data[i][9];

obj.getColumnTemplate(0).setStyle("color", myColor);
Alex (ActiveWidgets)
June 3,
Did you ever get it to work? What did you do to make it work if so? I have been tearing my hair out as well on this. What I want to do it change the color of a cell based on what radio button I click. Can you help? rprzybylski@msn.com

Richard Przybylski
March 24,
I've just tried it and it works perfectly.
June 29,
I tried it and didnt work:

function myColor(){
var i = this.getRowProperty("index");
return myData[i][4];

obj.getColumnTemplate(0).setStyle("color", myColor);
Daniel - Venezuela
July 7,
I am totally baffled by how this sets the color of a single cell. Can someone add some comments to this and/or show me an example that works.
Frank Gualtieri
September 2,
I use this code and it works for me.

Dim LCell As String
Dim LColorCells As String

For i = StartRow To EndRow
Range("RowIndex") = i

'Update Cell F66 based on Cell H64
LCell = "ColorName"
'Color will change in Cell F64
LColorCells = "Color"

Select Case Left(Range(LCell).Value, 6)

'Set cell color to dark blue
Case "Blue"
Range(LColorCells).Interior.ColorIndex = 11
Range(LColorCells).Interior.Pattern = xlSolid

'Set cell color to Orange
Case "Orange"
Range(LColorCells).Interior.ColorIndex = 46
Range(LColorCells).Interior.Pattern = xlSolid

'Set cell color to Red
Case "Red"
Range(LColorCells).Interior.ColorIndex = 3
Range(LColorCells).Interior.Pattern = xlSolid

'Set cell color to Yellow
Case "Yellow"
Range(LColorCells).Interior.ColorIndex = 6
Range(LColorCells).Interior.Pattern = xlSolid

'Set cell color to Green
Case "Green"
Range(LColorCells).Interior.ColorIndex = 10
Range(LColorCells).Interior.Pattern = xlSolid

'Set cell color to White
Case "White"
Range(LColorCells).Interior.ColorIndex = 2
Range(LColorCells).Interior.Pattern = xlSolid

'Set cell color to Black
Case "Black"
Range(LColorCells).Interior.ColorIndex = 1
Range(LColorCells).Interior.Pattern = xlSolid

End Select
Charlie DeHart
September 8,
The script works as long as I copy and paste it. It appears to be brilliantly simple. I just wish it taught me something so I could convert the knowledge to other purposes. I'll join Frank in asking, could someone comment on what it's doing.

If I want to use it to change a table instead of a row, what do I change?

function myColor(){
var i = this.getRowProperty("index");
return obj_data[i][9];

obj.getColumnTemplate(0).setStyle("color", myColor);
James Ainsworth
October 20,
<%// in JSP
String transbgNotMapped = "#123456";
String transbgMapped = "#654321"; %>

obj.defineDataProperty("color", function(i){ var trans = myData[i][10] ;
if(trans == "no" )return "<%=transbgNotMapped%>"; else return "<%=transbgMapped%>"
var row = new Active.Templates.Row ;
row.setStyle("background",function(){return this.getItemProperty("color")});
obj.setRowTemplate(row) ;


Rob Plater
October 20,
where can i see this script working?
i cant get it right...
Best regards,
December 18,
This worked for me - thanks for the info!
April 7,

This topic is archived.

See also:

Back to support forum


Version 2

Looking for AW 2.6 ?
The old site is here.