Hello,

You can try the following solution which makes use of an Item renderer for
datargrid.
It changes the background color of datagrid cell on dynamic basis ( using
properties of item renderer ). If you have fixed condition for changing the
cell color, then u can modity the item rendere according to your static
condition.

here is the code :

*MainApplication.mxml
------------------------------------*
**
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute"
initialize="" xmlns="*" >
<mx:Script>
<![CDATA[

 import mx.collections.ArrayCollection;
 import mx.rpc.events.ResultEvent;
 import mx.controls.Alert;
 import mx.core.ClassFactory;
 [Bindable]
 private var employeeData:ArrayCollection=new ArrayCollection();

// This value can be further set depending upon requirements.
// Assign value to this string variable as per you need

 *public var dynamicConditionValue:String = '51_142';
*

 private function resultHandler(event:ResultEvent):void
 {
    // ------------------ Get Result in Array Collection -------------------

    employeeData = event.result.coordinates.values;

    // ------- Set the property of Item Renderer using ClassFactory
---------

    var classFactoryVar:ClassFactory = new
ClassFactory(CustomBackgroundComp);
    classFactoryVar.properties = {threshold:dynamicConditionValue};
    firstColumn.itemRenderer = classFactoryVar;
 }

]]>
</mx:Script>
 <!--Send the HTTPService Request to get the employee data-->

<mx:HTTPService id="employeeService"   url="data/file.xml"
result="resultHandler(event)" />
<!--DataGrid-->
<mx:DataGrid id="dg" x="0" y="0" width="100%" dataProvider="{employeeData}"
>
  <mx:columns>
   <mx:DataGridColumn id="firstColumn" dataField="xval" headerText="x value"
/>
   <mx:DataGridColumn id="secondColumn" dataField="yval" headerText="y
value" />
  </mx:columns>
</mx:DataGrid>
<mx:Button x="60" y="248" label="Get Result" click="employeeService.send();"
/>
</mx:Application>

*file.xml
------------*

<?xml version="1.0"?>
<coordinates>
 <values xval="51" yval="54" />
 <values xval="142" yval="225" />
 <values xval="3" yval="148" />
 <values xval="254" yval="13" />
 <values xval="785" yval="18" />
 <values xval="46" yval="61" />
 <values xval="117" yval="183" />
 <values xval="8" yval="111" />
</coordinates>

*CustomBackgroundComp.as
---------------------------------------------*
*
*package {
       import flash.display.Graphics;

       import mx.controls.DataGrid;
       import mx.controls.Label;
       import mx.controls.dataGridClasses.*;

       public class CustomBackgroundComp extends Label {

       private var _threshold:String;

       override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
        {
                 super.updateDisplayList(unscaledWidth, unscaledHeight);

                  var g:Graphics = graphics;
                  g.clear();
                  var grid1:DataGrid =
DataGrid(DataGridListData(listData).owner);

                  if (grid1.isItemSelected(data) ||
grid1.isItemHighlighted(data))
   return;

                  var rendererArray:Array = new Array();
                  rendererArray = _threshold.split("_");

                  for(var ind:int=0; ind<rendererArray.length; ind++)
                  {
     if (data[DataGridListData(listData).dataField] == rendererArray[ind])
      {
           g.beginFill(0x3ea746);
           g.drawRect(0, 0, unscaledWidth, unscaledHeight);
           g.endFill();

          */* Here you can use the textField properties to change the text
color */*

        }
   }
}

       public function set threshold(value:String):void
         {
               _threshold = value;
         }
    }
}




I hope this will help you to solve your problem. Modify this code as per
your need.


Regards,

*Deepak
*



On Thu, Oct 7, 2010 at 4:42 AM, Sidhu Vijay Sidhu <[email protected]>wrote:

> hi i hve datagrid and in some cells i am displaying some text which it is
> taking from lable function now my requirement is that i need to change the
> color of those text too in all the cells where it is displaying but in label
> function i think we cannot set the style of the text... and there is no
> style function for datagrid pls help asap if anybdy have solution
>
> --
> 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]<flex_india%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/flex_india?hl=en.
>

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