PDA

View Full Version : How to change the colour of a Datagrid cell depending on cell previous & new value?


tanusree
09-25-2007, 03:43 PM
Here I' m passing data from server in the following format
sScriptName= "Nokia" + "|" + "20" + "|" +30;
Here from the server data is coming properly.

if(datagrid.dataprovider!=null)
{

var serverData : String =socket.readUTFBytes(socket.bytesAvailable);
var arrServerData :Array = serverData("|");


iRowno=0;
for each(var row: object in datageid.dataprovider)
{
if(row.name.indexof(arrServerData[0].tostring,0)!= -1)//Checking the company name
{
cellColourRenderer.vPrevOpen = row.open.tostring(); //Here open is one my column name in the datagrid & i'm storing it's value in the variable which is decalred in theActioscript class
arrItems.setItemAt({name:arrServerData[0].tostring,open:arrServerData[1].tostring,high:arrServerData[2].tostring,low:arrServerData[3].tostring,arrServerData[4].tostring},iRowno);
break; //Here updating the datagrid
}
iRowno++;
}
}


My datagrid is like this ---
<mx:datagrid id="datagrid">
<columns>
<mx:datagridcolumn headertext="name" datafield="name" />
<mx:datagridcolumn headertext="open" datafield="open" itemrenderer="CustomBackgroundComp"/>

</columns>
</mx:datagrid>



MY Actionscript code CustomBackgroundComp.as

package {
import mx.controls.Label;
import mx.controls.DataGrid;
import mx.controls.dataGridClasses.DataGridListData;
import flash.display.Graphics;

public class CustomBackgroundComp extends Label
{
public static var vPrevOpen : string;

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
var g:Graphics = graphics;



if (data[DataGridListData(listData).dataField] ="")
{
g.beginFill(0x000000);
g.drawRect(0, 0, unscaledWidth, unscaledHeight);
g.endfill();
}


else if (data[DataGridListData(listData).dataField] >= VprevOpen)
{
g.beginFill(0x009900);
g.drawRect(0, 0, unscaledWidth, unscaledHeight);
g.endFill();
}

else if (data[DataGridListData(listData).dataField] VprevOpen)
{
g.beginFill(0xFF0000);
g.drawRect(0, 0, unscaledWidth, unscaledHeight);
g.endFill();
}


}
}
}


here my problem is that if there are 2 rows it will change the color of two rows simultaneously but it should change the color of a single row at a time.can anyone help me regarding this problem .