5/11/2010 4:27:31 AM
Title:
how to change background color of specific rows in datagrid in flex
hey frnds,
how to change background color of specific rows in datagrid in flex
like if i'm clicking on button then i want to change bckground color of 1st, 4rth row of datagrid.
thx in advanced,
:)
Inder
Points: 2880
Posts:0
5/11/2010 6:30:39 AM
first you need to extend the DataGrid class. below is the code of extended class.
//class dataGridRowBackground.as
package
{
import flash.display.Sprite;
import mx.controls.DataGrid;
public class dataGridRowBackground extends DataGrid
{
public function dataGridRowBackground()
{
super();
}
public function setRowBackgroundColor(rowIndex:Number,color:uint):void{
var rowBGs:Sprite=Sprite(listContent.getChildByName("rowBGs"));
drawRowBackground(rowBGs,rowIndex,listContent.rowInfo[rowIndex].y,listContent.rowInfo[rowIndex].height,color,null);
}
}
}
you can set color in actionscript using setRowBackgroundColor function :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*">
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridColumn;
protected function button4_clickHandler(event:MouseEvent):void
{
dataGrid.setRowBackgroundColor(3,0xcccccc);
}
]]>
</mx:Script>
<mx:ArrayCollection id="arrColl">
<mx:source>
<mx:Array>
<mx:Object name="SUV" value="Automobile" />
<mx:Object name="Motorcycle" value="Automobile" />
<mx:Object name="Cycle" value="Automobile" />
<mx:Object name="Car" value="Automobile" />
<mx:Object name="Bus" value="Automobile" />
<mx:Object name="Jeep" value="Automobile" />
<mx:Object name="Truck" value="Automobile" />
</mx:Array>
</mx:source>
</mx:ArrayCollection>
<local:dataGridRowBackground id="dataGrid" dataProvider="{arrColl}" verticalScrollPolicy="on">
</local:dataGridRowBackground>
<mx:Button label="Set background color of Row" click="button4_clickHandler(event)"/>
</mx:Application>
5/11/2010 11:59:44 PM
thx frnd,
its really nice example ,
:)