本文介绍了如何动态更改数据网格行的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎有各种黑客可以改变数据网格行的背景颜色,但所有这些似乎都发生在渲染时.

It seems like there are various hacks out there to change the background colour of the row of a datagrid but all of them seem to happen at render time.

请参阅:在 Adob​​e Flex 中设置数据网格行的背景颜色

我有一个数据网格,我需要将行颜色更改为红色,然后根据绑定 ArrayCollection 的更改频繁地恢复正常.所以我正在寻找一种动态更改行颜色的方法.

I have a datagrid where I need to change row colours to red then back to normal frequently based on changes to the bound ArrayCollection. So I'm looking for a way to change the row colours dynamically.

有人可以帮忙吗?显然,由于更改经常发生,如果更改行的背景颜色不是一个昂贵的过程就好了,但乞丐不能选择.

Can anyone help? Obviously as the changes are happening frequently it would be nice if changing the background colour of the row wasn't an expensive process, but beggar's can't be choosers.

推荐答案

您必须编写自定义组件,我将包含我们项目中经过清理的代码.在 ActionScript 中的某处,您需要为每一列编写此内容:

You'll have to write a custom component, I'll include sanitized code from our project. Somewhere in your ActionScript, you'll need to write this for each column:

column.itemRenderer = new ClassFactory(CellRenderer);

这是自定义类:

public class CellRenderer extends Label {
    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
        super.updateDisplayList(unscaledWidth, unscaledHeight);
        var g:Graphics = graphics;
        g.clear();
        for each(var object:Object in arrayCollection) {
            if (object.rowIndex == 0) { //or whatever your conditions are
                g.beginFill(0xFFFFC0);
                g.drawRect(0, 0, unscaledWidth, unscaledHeight);
                g.endFill();
            }
        }
    }
}

这篇关于如何动态更改数据网格行的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 03:14