DataGrid 技巧:更改某一行的背景色 DataGrid skills: change the background color of a line
10月11th, 2006 — Dreamer 10月11 th, 2006 - Dreamer在Peter Ent那里看到一个关于DataGrid的技巧,很有用。 In Peter Ent there to see a DataGrid on the skills and useful. 文章比较短,直接翻译在这里好了。 The article rather short, direct translation of the good here.
原文地址:http://weblogs.macromedia.com/pent/archives/2006/10/datagrid_tip_ro.cfm Original Address: http://weblogs.macromedia.com/pent/archives/2006/10/datagrid_tip_ro.cfm
DataGrid 技巧:行的背景色 DataGrid skills: the background color line
如何更改DataGrid中某一行的背景色是一个被经常问的问题。 How can I change DataGrid in a line of the background color was a frequently asked questions. 这个在Flex2.0中很简单,只需按照下面的步骤做: Flex2.0 this in a very simple, just follow the steps below to do:
1.创建一个扩展自mx.controls.DataGrid 的类。 1. Mx.controls.DataGrid since the creation of an expansion of the category. 这个类可以是MXML文件或者ActionScript文件,你可以根据自己的习惯创建。 This class can be ActionScript MXML document or file, you can create according to their own habits.
2.覆写protected 方法drawRowBackground : 2. Override protected methods drawRowBackground:
override protected function drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void override protected function drawRowBackground (s: Sprite, rowIndex: int, y: Number, height: Number, color: uint, dataIndex: int): void
{ (
// 这里可以做一些对数据的判断,然后更改相应的颜色。 / / You can do some data on the judgement, and then change the corresponding color. 比如color = 0xFF0000; For example, color = 0xFF0000;
// 调用super函数来执行更改。 / / Call super function to implement changes.
super.drawRowBackground(s,rowIndex,y,height,color,dataIndex); super.drawRowBackground (s, rowIndex, y, height, color, dataIndex);
} )
3.在你的程序中用你新建的类替代<mx:DataGrid>。 3. In the process you used your new category of alternative <mx: DataGrid>.
在drawRowBackground 方法中你可以对数据做一些判断。 In drawRowBackground methods of data you can do some judgement. dataIndex 参数可以用来查看dataProvider 中某一行所显示的数据。 dataIndex dataProvider parameters can be used to check in a line shown by the data. 例如:假设你想要将数值大于1000的行都显示为绿色: For example: Suppose you want to value more than 1000 shows that the line for the Green:
var item:Object = (dataProvider as ArrayCollection).getItemAt(dataIndex); var item: Object = (dataProvider as ArrayCollection). getItemAt (dataIndex);
if( item.quantity > 1000 ) color = 0×00FF00; if (item.quantity> 1000) color = 0 × 00FF00;
就这么简单。 It's that easy.
本文链接: http://www.zhuoqun.net/html/y2006/271.html 转载请注明出处,谢谢。 This link: http://www.zhuoqun.net/html/y2006/271.html reprint please reference, thank you.
TrackBack引用地址: http://www.zhuoqun.net/html/y2006/271.html/trackback TrackBack used Address: http://www.zhuoqun.net/html/y2006/271.html/trackback


