在使用DataGrid/AdvancedDataGrid我们有时候会需要以指定的条件显示行的背景色..达到突出显示的效果..
下面是两种常用的应用..


一.跟据指定的字段数据,条件显示指定的行的指定背景色..
下面这个是根据成绩的字段.,低于60分即显示橙红色..

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml">  
  3.     <mx:Script>  
  4.         <!--[CDATA[  
  5.             override protected function drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void  
  6.             {  
  7.                 var list:XMLList = new XMLList(dataProvider)  
  8.                 if(dataIndex < list.length() && list[dataIndex].@result<60)color = 0xFF6600  
  9.                 super.drawRowBackground(s,rowIndex,y,height,color,dataIndex);  
  10.             }  
  11.         ]]-->  
  12.     </mx:Script>  
  13. </mx:DataGrid>  

 

二.根据单双行显示隔行颜色..

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml">  
  3.     <mx:Script>  
  4.         <!--[CDATA[  
  5.             override protected function drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void  
  6.             {  
  7.                 if(dataIndex%2==0)color = 0xcccccc  
  8.                 super.drawRowBackground(s,rowIndex,y,height,color,dataIndex);  
  9.             }  
  10.         ]]-->  
  11.     </mx:Script>  
  12. </mx:DataGrid>