如何动态更改datagrid行的背景颜色?

编程入门 行业动态 更新时间:2024-10-28 19:26:01
本文介绍了如何动态更改datagrid行的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

看起来有各种各样的hack可以改变datagrid的行的背景颜色,但是所有这些都似乎在渲染时发生。 :在Adobe Flex中为datagrid行设置背景颜色

我有一个datagrid,我需要将行颜色更改为红色,然后根据绑定ArrayCollection的更改频繁返回正常。所以我正在寻找一种动态改变行颜色的方法。

任何人都可以帮助?显然,随着变化的频繁发生,如果改变行的背景颜色不是一个昂贵的过程,但是beggar不能作为选择器,这将是很好的。

解决方案

您必须编写一个自定义组件,我将包含来自我们项目的已清理代码。在您的ActionScript中的某个地方,您需要为每个列写入:

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(); 每个(var object:array in arrayCollection){ if(object.rowIndex == 0){//或者你的条件是 g.beginFill(0xFFFFC0); g.drawRect(0,0,unscaledWidth,unscaledHeight); g.endFill(); } } } }

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.

See: Setting background color for datagrid row in Adobe Flex

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.

解决方案

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);

Here's the custom class:

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(); } } } }

更多推荐

如何动态更改datagrid行的背景颜色?

本文发布于:2023-11-11 10:07:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578119.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:颜色   背景   动态   datagrid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!