数据网格 FLEX 中的不同行样式

问题描述:

如果在数据字段中找到某个单词,我正在尝试更改数据网格中一行的字体颜色.有没有一种简单的内联方式来做到这一点?

I'm trying to change the font color of a row in a datagrid if a certain word is found in a datafield. Is there a simple, inline way to do this?

谢谢

您可以覆盖您的 DataGrid 的 drawRowBackground 方法,并检查它是否需要自定义背景.
如果是,则将新的背景颜色传递给此方法的 super 调用:

You can override your DataGrid's drawRowBackground method, and check whether it needs custom background or not.
If so, pass the new background color to the super call of this method:

protected override function drawRowBackground(s:Sprite, rowIndex:int, 
    y:Number, height:Number, color:uint, dataIndex:int):void
{
    if ((dataProvider[dataIndex] as String).indexOf(someWord) >= 0)
        color = yourCustomColor;
    super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);
}

其中 someWord 是您要搜索的单词,而 yourCustomColor 是表示新背景颜色的 uint,例如:

where someWord is the word you are searching for, and yourCustomColor is the uint representing the new background color, eg:

var yourCustomColor: uint = 0xff0000;