1 Reply Latest reply on Nov 14, 2007 5:57 AM by

    how can I dynamically change a Grids ro color

    ljonny18 Level 1
      Hi,

      I am using a grid within a component in my Flex application.

      I have an XML dataProvider, and I want to change the row colour of my Grid depending on a value coming form my dataProvider – but I cant seem to get this to work :(

      can anyone help / advise me on how I can dynamically change the colour of my grid row depending on a value coming from my XML DataProvider????


      For example:
      Within my component I have the following grid within an “MXML” component called myGrid.mxml:

      [CODE]<mx:Grid id="GGrid">
      <mx:GridRow backgroundColor="0xCFD8DA">
      <mx:GridItem>
      <mx:Label id=”name_lbl”/>
      </mx:GridItem>
      </mx:GridRow>
      <mx:GridRow backgroundColor="0xCFD8DA">
      <mx:GridItem>
      <mx:Label id=”expiryDate_lbl”/>
      </mx:GridItem>
      </mx:GridRow>

      <mx:GridRow id=”statusRow”>
      <mx:GridItem>
      <mx:Label id=”status_lbl”/>
      </mx:GridItem>
      </mx:GridRow>
      </mx:Grid>[/CODE]


      I am setting/declaring my results/variables form my dataProvider in the main Application (“MXML”) file:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application
      xmlns:mx=" http://www.adobe.com/2006/mxml"
      xmlns="*"
      creationComplete="initApp()" >

      <mx:HTTPService
      id="myResults"
      url=" http://localhost/myResults.xml"
      resultFormat="e4x"
      result="myResultHandler(event)" />


      [CODE]<mx:Script>
      <![CDATA[

      import mx.core.Application;

      [Bindable]
      public var myDataFeed:XML;


      public function initApp():void
      {
      myResults.send();
      }

      public function myResultHandler(event:ResultEvent):void
      {
      myDataFeed = event.result as XML;

      Application.application.myGrid.name_lbl.text = myDataFeed.name;
      Application.application.myGrid.expiryDate_lbl = myDataFeed.expiry;
      Application.application.myGrid.status_lbl.text = myDataFeed.status;
      }


      if(myDataFeed.status == “OK”)
      {
      Application.application.statusRow.backgroundColor="0xCFD8DA";
      }
      else if (myDataFeed.status == “WARNING”)
      {
      Application.application.statusRow.backgroundColor="0xFF9900";
      }
      else if (myDataFeed.status == “CRITICAL”)
      {
      Application.application.statusRow.backgroundColor="0xFF0000";
      }
      ]]>
      </mx:Script>
      </mx:Application>[/CODE]



      however, I cannot access the property “backgroundColor” of the gridRow in this way:

      [CODE]Application.application.statusRow.backgroundColor[/CODE]

      As I get the following error:

      [CODE]Severity and Description Path Resource Location Creation Time
      Id 1119:

      Access of possibly undefined property backgroundColor through a reference with static type mx.containers:GridRow. enterpriseDB_new enterpriseDB_new.mxml

      line 721 1194443056449 19295[/CODE]

      can anyone help / advise me on how I can dynamically change the colour of my grid row depending on a value coming from my XML DataProvider????


      Thanks,
      Jon.
        • 1. Re: how can I dynamically change a Grids ro color
          quote:

          Originally posted by: ljonny18
          Hi,

          I am using a grid within a component in my Flex application.

          I have an XML dataProvider, and I want to change the row colour of my Grid depending on a value coming form my dataProvider – but I cant seem to get this to work :(

          can anyone help / advise me on how I can dynamically change the colour of my grid row depending on a value coming from my XML DataProvider????

          ...

          Thanks,
          Jon.



          Hi,
          a few hours ago I stumbled across this cookbook entry - it didn't solve MY problem, but maybe it provides a way to solve your problem?

          http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&postId=61&product Id=2&loc=en_US

          From the article:

          quote:

          Changing the background color of a DataGrid cell is not as simple as changing some style because the default renderer for a DataGrid cell does not have a backgroundColor. Therefore, to do this simple task, you have to create a custom itemRenderer where you draw your own background in the updateDisplayList function.


          HTH

          Uwe