Hey Tracy,
I wonder if his has anything to do with it.
override public function get data():Object
{
return this.selected;
}
-TH
--- In [email protected], "Tracy Spratt" <[EMAIL PROTECTED]> wrote:
>
> 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
> variable. 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"
> 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>
>