Hi sidu,

Vikas code is simple and straight fwd. It works great and was useful for me.
I made a little tweak to that. If any one wanna highlight not only the text
but also the background of the cell. Then they can use the code below. The
credit goes to Vikas.

************************************************************************
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
                layout="absolute">
    <mx:HBox width="100%" height="100%" backgroundColor="#C8CBCC"
             verticalAlign="middle" horizontalAlign="center">
        <mx:DataGrid id="cusipGrid" width="500" height="300"
                     dataProvider="{employeeRecord}">
            <mx:columns>
                <mx:DataGridColumn headerText="Employee Name"
                                   dataField="EmployeeName" />
                <mx:DataGridColumn headerText="Employee Age"
                                   dataField="EmployeeAge"
itemRenderer="asCode.ColoredText"/>
            </mx:columns>
        </mx:DataGrid>
    </mx:HBox>

    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            [Bindable]
            private var employeeRecord:ArrayCollection      = new
ArrayCollection(
                [{EmployeeName : "emp1" , EmployeeAge : 25 },
                    {EmployeeName : "emp2" , EmployeeAge : 68 },
                    {EmployeeName : "emp3" , EmployeeAge : 15 },
                    {EmployeeName : "emp4" , EmployeeAge : 12 },
                    {EmployeeName : "emp5" , EmployeeAge : 28 },
                    {EmployeeName : "emp6" , EmployeeAge : 71 }]
            );

        ]]>
    </mx:Script>
</mx:Application>

****************************************************************************


Now make a class ColoredCell in asCode package Which extends Label
class.


**************************************************************************

package asCode
{
    import mx.controls.TextInput;

    public class ColoredText extends TextInput
    {
        private const WHITE_COLOR:uint = 0xFFFFFF;
        private const BLACK_COLOR:uint = 0x000000;
        private const RED_COLOR:uint = 0xFF0000;
        public function ColoredText()
        {
            super();
        }
        override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
        {
            super.updateDisplayList(unscaledWidth,unscaledHeight);
            var empName:String = data.EmployeeName;
            if(empName=="emp1")
            {// for highlighting the odd man out
                setStyle("contentBackgroundColor",RED_COLOR);
                setStyle("color",WHITE_COLOR);
            }else setStyle("color",BLACK_COLOR);

                setStyle("textAlign","right");
                setStyle("textWeight","bold");
        }
    }
}

***********************************************************************

-- 
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en.

Reply via email to