Title: changing background color of a cell in datagrid

colorRenderer.mxml

<mx:VBox xmlns:mx="http://www.macromedia.com/2003/mxml" mouseDown="updateColor()" width="100%">

 <mx:Script>

 <![CDATA[

 var getCellIndex:Function;

 var listOwner:MovieClip;

 

 var colorCount:Number = 0;

 

 static var colors:Array = [0xff0000, 0x00ff00, 0x0000ff];

 

 function setValue(str:String, item:Object, sel:Boolean){

     this.setStyle("backgroundColor", item.cellBackColor)

     myLabel.text = str;

 }

 

 function updateColor() {

     listOwner.dataProvider.editField(getCellIndex().itemIndex, "cellBackColor", colors[colorCount++ % 3]);

 }

 ]]>

 </mx:Script>

 

 <mx:Label id="myLabel" />

 

</mx:VBox>

 

 

Note that the clicking only works over the Label the first time but the whole cell once the color has changed once.  I’ll let you debug it further…

 


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Parekh, Shweta - BLS CTR
Sent: Thursday, December 08, 2005 11:44 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] changing background color of a cell in datagrid

 

Hi,

Can anyone send me some sample code / point to some sample code to change the background color of a cell in a datagrid when the cell is clicked.

I have tried writing a custom cellRenderer for this but with no luck.

class MyCellRenderer extends UIComponent
{      
        var listOwner : MovieClip; // the reference we receive to the list
        var text_c:MovieClip;  
        var getCellIndex : Function; // the function we receive from the list
        var celltext : mx.controls.Text;
       

  function MyCellRenderer()
  {
                text_c = createClassObject(Text, "celltext", 1, { styleName:this, owner:this }); 
  }
 
  function setValue(theValue:String, theItem:Object, selected:String):Void
  {
          trace("in setValue, theValue:" + "selected: "+selected );
          text_c.text = theValue;
          text_c.visible = true;

          listOwner.dataProvider.editField(getCellIndex().columnIndex, "backgroundColor", 0xCC66FF);
  }

Thanks in advance,
Shweta




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to