Note that there are some explanatory texts on larger screens.

plurals
  1. POFlex: CheckBoxes in DataGrid not updating after change in binded ArrayCollection
    primarykey
    data
    text
    <p>I have extended CheckBox class to use it as itemRenderer to centered it in DataGrid cell and reflect ArrayCollection changes. Here is the .as:</p> <p>package myComponents { import flash.display.DisplayObject; import flash.text.TextField;</p> <pre><code>import mx.controls.CheckBox; import mx.controls.dataGridClasses.DataGridListData; import mx.controls.listClasses.BaseListData; import mx.controls.listClasses.IDropInListItemRenderer; import mx.managers.IFocusManagerComponent public class myCheckBox extends CheckBox implements IDropInListItemRenderer//,IFocusManagerComponent { private var _listData:DataGridListData; public function myCheckBox() { super(); } override protected function updateDisplayList(w:Number, h:Number):void { super.updateDisplayList(w, h); var n:int = numChildren; for (var i:int = 0; i &lt; n; i++) { var c:DisplayObject = getChildAt(i); if (!(c is TextField)) { c.x = (w - c.width) / 2; c.y = 0; } } } // Implement the drawFocus() method for the VBox. /* override public function drawFocus(draw:Boolean):void { setFocus(); }*/ [Bindable] override public function set data(value:Object):void{ super.data = value; selected=data[_listData.dataField]; } override public function get data():Object { return super.data; } override public function get listData():BaseListData { return _listData; } override public function set listData(value:BaseListData):void { _listData = DataGridListData(value); } } </code></pre> <p>}</p> <p>In the application I bind it with an array collection:</p> <p> <pre><code> [Bindable] private var myAC:ArrayCollection = new ArrayCollection([ {id:89, Seccion: 'Bob Jones', Leer: true , Escribir: true , Eliminar: false}, {id:5, Seccion: 'Jane Smith', Leer: true , Escribir: false , Eliminar: false}, {id:7, Seccion: 'Doug Johnson', Leer: false , Escribir: true , Eliminar: true}, {id:15, Seccion: 'John Jackson', Leer: true , Escribir: false , Eliminar: false}, {id:21, Seccion: 'Christina Coenraets', Leer: true , Escribir: true , Eliminar: false}, {id:4, Seccion: 'Joanne Wall', Leer: false , Escribir: false , Eliminar: true}, {id:461, Seccion: 'Maurice Smith', Leer: false , Escribir: false , Eliminar: false}, {id:35, Seccion: 'Lorraine Barnes', Leer: true , Escribir: true , Eliminar: true}, {id:61, Seccion: 'The Dude', Leer: true , Escribir: false , Eliminar: true}, {id:56, Seccion: 'Abe Rockaway', Leer: true , Escribir: true , Eliminar: false} ]); private function init():void{ myAC.addEventListener(CollectionEvent.COLLECTION_CHANGE, onChange); myAC.enableAutoUpdate(); } private function onChange(event:CollectionEvent):void { //myAC.disableAutoUpdate(); var obj:Object=event.items[0].source; var i:uint=myAC.getItemIndex(obj); switch (event.items[0].property) { case "Leer": if(obj["Leer"]==false) { obj["Escribir"]=false; obj["Eliminar"]=false; } break; case "Escribir": if(obj["Escribir"]==false) obj["Eliminar"]=false; else myAC[i]["Leer"]=true; break; case "Eliminar": if(obj["Eliminar"]==true) { obj["Escribir"]=true; obj["Leer"]=true; } break; default: break; } // myAC.enableAutoUpdate(); myAC.itemUpdated(obj); //myGrid.validateNow(); } ]]&gt; &lt;/mx:Script&gt; &lt;mx:DataGrid id="myGrid" dataProvider="{myAC}" editable="true" &gt; &lt;mx:columns&gt; &lt;mx:DataGridColumn dataField="Seccion" width="150" headerText="Sección"/&gt; &lt;mx:DataGridColumn dataField="Leer" width="100" headerText="Leer" itemRenderer="myComponents.myCheckBox" rendererIsEditor="true" editorDataField="selected"/&gt; &lt;mx:DataGridColumn dataField="Escribir" width="100" headerText="Escribir" itemRenderer="myComponents.myCheckBox" rendererIsEditor="true" editorDataField="selected"/&gt; &lt;mx:DataGridColumn dataField="Eliminar" width="100" headerText="Eliminar" itemRenderer="myComponents.myCheckBox" rendererIsEditor="true" editorDataField="selected"/&gt; &lt;/mx:columns&gt; &lt;/mx:DataGrid&gt; &lt;mx:TextArea id="cellInfo" width="300" height="150"/&gt; &lt;mx:Label id="lb" text=""/&gt; </code></pre> <p></p> <p>The onChange function is the handler for COLLECTION_CHANGE. In this function I make changes to myAC (arrayCollection) binded to the dataGrid. These changes should check or uncheck the affected checkboxes, but the display of these checkboxes are only updated after scrolling them out and in the dataGrid display area.</p> <p>I don´t want to put the checkboxes in a canvas or any container.</p> <p>Why are not the checkboxes updated after myAC.itemUpdated?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload