2008-11-13
3020
小小貝,小小貝,小小貝,小小貝,小小貝,小小貝,小小貝,小小貝,小小貝,小小貝,小小貝,小小貝,小小貝,小小貝
如何更改DataGrid中某一行的背景色是一個被經常問的問題。這個在Flex2.0中很簡單,只需按照下面的步驟做:
1.創建一個擴展自 mx.controls.DataGrid 的類。這個類可以是MXML文件或者ActionScript文件,你可以根據自己的習慣創建。
2.覆寫 protected 方法
drawRowBackground :
override protected function drawRowBackground(s:Sprite, rowIndex:int,
y:Number,height:Number, color:uint, dataIndex:int):void
{// 這里可以做一些對數據的判斷,然后更改相應的顏色。比如color = 0xFF0000;
// 調用super函數來執行更改。
super.drawRowBackground(s,rowIndex,y,height,color,dataIndex);}
3.在你的程序中用你新建的類替代 <mx:DataGrid>。
在 drawRowBackground 方法中你可以對數據做一些判斷。dataIndex 參數可以用來查看dataProvider 中某一行所顯示的數據。例如:假設你想要的數值大于1000的行都顯示為綠色:
var item:Object = (dataProvider as ArrayCollection).getItemAt(dataIndex);if( item.quantity > 1000 ) color = 0×00FF00;
就這么簡單。