小小菜鸟的web菜园子

web开发学习。好记性不如烂笔头。每天进步一点点!

导航

FLEX:改变DataGrid行的背景色

 

如何更改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;

就这么简单。

posted on 2008-10-29 15:57  『小小菜鸟』  阅读(3095)  评论(0编辑  收藏  举报