LOL!

Your analysis makes perfect sense. My workaround is working fine, so no
sweat.

Tracy

 

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Alex Harui
Sent: Wednesday, August 27, 2008 9:21 PM
To: [email protected]
Subject: RE: [flexcoders] DataGrid change handler: event.selectedItem ==
true???? w/ CheckBox renderer

 

I think there are times where the DG will pull the data property from
the renderer assuming it is the dataprovider item, which in your case it
isn't.  Maybe we shouldn't do that, but it doesn't matter since Scene7
is going to take over the world :-)

 

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Tracy Spratt
Sent: Wednesday, August 27, 2008 6:13 PM
To: [email protected]
Subject: [flexcoders] DataGrid change handler: event.selectedItem ==
true???? w/ CheckBox renderer

 

I have a moderately complex standard DataGrid, using an
XMLListCollection dataProvider.  In the DG change event handler, I
assign a reference to the selectedItem(an XML node) to an instance
variabl! e.  One column of the DG is a CheckBox ItemRenderer.

On the first interaction with the DG, if I directly click the checkbox,
without first selecting that row,  the event.target.selectedItem is the
Booean value, "true", and not the XML node I expect.  If I select the
row first, then click the CheckBox renderer, the
event.target.selectedItem is the xml! node I want.

event.target.selectedIndex is reported correctly, so I have a
work-around, but does anyone have any suggestions about why this might
be happening?  I have never seen anything like this before, and have
done similar stuff a lot.

Obviously, I suspect the CheckBox item renderer is playing a role, and
will investigate further, but, any thoughts?  The mxml item renderer is
pretty short so I'll post it below.

Tracy

 

<?xml version="1.0" encoding="utf-8"?>

<!-- RendererCheckBox

  special version, uses Status code (W,A) to set/save value -->

<mx:CheckBox xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> "

        click="onClick()">

        

<mx:Script><![CDATA[

  import mx.controls.dataGridClasses.DataGridListData

  public var _xmlItem:XML;    //holds the current item xml node

  private var _dgListData:DataGridListData; 

  private var _sDataField:String

  

  public var value:String = "W";

  

  //Sets the state of the checkbox to the value of the selected
attribute

  //If there is no selected attribute, create on and set it to false

  override public function set data(oItem:Object):void

  {

    _xmlItem = XML(oItem);

    _dgListData = DataGridListData(listData);

    _sDataField = _dgListData.dataField;

    var sStatusCode:String = _xmlItem[_sDataField];

    var bSelected:Boolean = (sStatusCode == "A");

    this.selected = bSelected;                        //set the checkbox
state to the local var

  }//set data

  

  /**

   *  center the contentHolder

   */

  override protected function updateDisplayList(w:Number, h:Number):void

  {

    super.updateDisplayList(w, h);

    var n:int = numChildren;

    for (var i:int = 0; i < n; i++)

    {

      var c:DisplayObject = getChildAt(i);

      if (!(c is TextField))

      {

        c.x = (w - c.width) / 2;

        c.y = 0;

      }

    }

  }  

  

  override public function get data():Object

  {

    return this.selected;

  }//

  //called by click of the checkbox

  private function onClick():void

  {

    if (this.selected)  {

      _xmlItem[_sDataField] = "A";

    }

    else  {

      _xmlItem[_sDataField] = "W";

    }

    dispatchEvent(new Event("IRCbxApprovedClick", true));

  }

                

]]></mx:Script>

        

</mx:CheckBox>

 

Reply via email to