English 中文(简体)
如果行为空, 则禁用高级 DataGrid 的交替项目颜色属性
原标题:Disable alternatingItemColor property for AdvancedDataGrid if the rows are empty

我有一个自定义的高级 DataGrid, 我们使用交替项目颜色属性, 该属性显示高级 DataGrid 行的两种不同颜色。 现在数据格有 15 行, 但只有 5 行有数据, 我们只想要前 5 行显示交替颜色, 其余的只显示一个颜色 。 过去有没有人这样做过, 如果有人能解释如何这样做, 将会非常感激 。

提前感谢。

问题回答

如果行 Ind 超过行数, 您必须覆盖数据格, 并覆盖绘图RowBackflor 方法。 然后设置默认颜色。 请参看下面提到的代码片断 :

public class CustomDataGrid extends AdvancedDataGrid {

    protected override function drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void{
          var XMLdata:XML=rowNumberToData(dataIndex) as XML;                       
          if(XMLdata!=null){                  
                    if(XMLdata.attribute(Constants.col) != undefined && XMLdata.attribute(Constants.col) != ""){
                                    color=XMLdata.attribute(Constants.col);                 
                    }else{
                            color=0xFFFFFF;
                    }                                            
          }                       
          super.drawRowBackground(s,rowIndex,y,height,color,dataIndex);                 
    }               
}

当行数少于允许的高度时, 将行数设为实际行数, 或者覆盖 drawRowBackform 。

尝试为您的 ATG: - 使用项目创建器 : - NAG: - NAME OF TRANSLATORS

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
               >
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.events.FlexEvent;

            [Bindable]
            private var dpHierarchy:ArrayCollection= new ArrayCollection([
                {name:"A", region: "Arizona"},
                {name:"B", region: "Arizona"},
                {name:"C", region: "California"},
                {name:"D", region: "California"}
            ]); 

        ]]>
    </fx:Script>

    <mx:AdvancedDataGrid id="myADG" 
                         width="500" height="500" 
                         paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0"
                         dataProvider="{dpHierarchy}"
                         itemRenderer="DrawAlternateRowColor">
        <mx:columns>
            <mx:AdvancedDataGridColumn dataField="name" headerText="Name" />
            <mx:AdvancedDataGridColumn dataField="region" headerText="Region" />
        </mx:columns>   

    </mx:AdvancedDataGrid>

</s:Application>

/项目设计人姓名: - 绘制不同的彩色- 您可以使用相同的概念与 CADG 使用 。

<?xml version="1.0" encoding="utf-8"?>
<s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                  xmlns:s="library://ns.adobe.com/flex/spark" 
                                  xmlns:mx="library://ns.adobe.com/flex/mx" 
                                  focusEnabled="true" alternatingItemColors="[#0000FF, #FF0000]"
                                  width="100%" height="100%">
    <s:Label id="lblData"  verticalAlign="middle" text="{listData.label}" />
</s:MXAdvancedDataGridItemRenderer>




相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Multiple Remote call made simultenously

I was making multiple remote calls and they are done sequentially and when I am getting a result event back it s triggering calls to all the methods with ResultEvent as an argument . I am supposed to ...

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Clearing RSL in Cache

I have built a flex application which has a "main" project and it is assosciated with a few RSL s which are loaded and cached once i run my "main" application. The problem i am facing is that the ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签