设置背景,选中效果只能是高亮一条,多条高亮只能设置背景来达到效果。但是原生的DataGrid根本无法达到所要的效果,目前一般就是来改写原生的DataGrid,只需重新写一个类来重写drawRowBackground方法就可以了,代码如下
package
org.lxh&nbs
p; {
import flash.dis
play.
sprite;
import mx.controls.DataGrid;
p
ublic class S
PEcialDataGrid extends DataGrid
{
PRivate
VAR _rowColorFunction:Function; //用于在外部能通过指定一个方法 去实现
改变列的背景色
public function SpecialDataGrid()
{
super();
}
public function set rowColorFunction(f:Function):void
{
this._rowColorFunction = f;
}
public function get rowColorFunction():Function
{
return this._rowColorFunction;
}
//复写该方法
override protected function drawRowBackground(s:Spr
ITe,rowIndex:int,y:Number, h
eight:Number, color:uint, dat
aindex:int):void
{
if( this.rowColorFunction != null ){
if( dataIndex < this.dataProvider.length ){
var item:Object = this.dataProvider.getItemAt(dataIndex);
color = this.rowColorFunction.call(this, item, color);
}
}
super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);
}
}
}
<control:SpecialDataGrid id="planDataGrid" width="100%" height="100%" alternatingItemColors="[0xe3ea
f2,0xe8
F1f8]" dataProvider="{strArray}" rowColorFunction="colorFunction" doubleClick="planDataGrid_doubleClickHandler(event)" doubleClickEnabled="true">
<control:columns>
<
;mx:DataGr
IDColumn dataField="选择" width="50" sortable="false" resizable="false" showDataTips="true">
<mx:itemRenderer>
<fx:
component>
<mx:CheckBox change="outerDocument.checkChangeHandlerForPlan(event)"/>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="id" headerText="主键" visible="false"/>
</control:columns>
</control:SpecialDataGrid>
private function colorFunction(item:Object, color:uint):uint
{
var col:uint=0xe3eaf2;
if(commonMsg.length > 0){
for(var i:int=0;i<commonMsg.length;
i++){
if(commonMsg.getItemAt(i).id
==item.id){
col=0xF10026;
}
}
}
return col;
}