I was able to get it working in one case using "itemUpdated." I had to
change the ArrayCollection to public, and then set the handler:
[Bindable]
public var colors:ArrayCollection = new ArrayCollection([
{color:"Red", display: true},
{color:"Blue", display: true},
{color:"Green", display: true}
]);
private function init():void {
colors.addEventListener(CollectionEvent.COLLECTION_CHANGE,
onChange);
}
.
.
.
<mx:DataGridColumn dataField="display" rendererIsEditor="true"
editorDataField="selected">
<mx:itemRenderer>
<mx:Component>
<mx:CheckBox label="{data.color}" selected="true"
click="data.display = selected; outerDocument.colors.itemUpdated(data);"
/>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
I still cannot get it working in the more complex case where I have a
more complex component item renderer:
<mx:DataGrid id="colorDG" dataProvider="{colors}" editable="true">
<mx:columns>
<mx:DataGridColumn headerText="Color" dataField="display"
rendererIsEditor="true" editorDataField="cbSelected">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="left" paddingLeft="5">
<mx:Script>
<![CDATA[
[Bindable]
public var cbSelected:Boolean;
]]>
</mx:Script>
<mx:CheckBox id="displayCheckBox"
selected="true" change="cbSelected = displayCheckBox.selected;
outerDocument.colors.itemUpdated(data);" />
<mx:Label text="{data.color}" />
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
When I click the checkbox in the above example, the COLLECTION_CHANGE
event is fired three times: the 1st and 3rd time with the prior (wrong)
value and the middle time with the updated (correct) value. When I use
"data.selected = displayCheckBox.selected" the event is fired anywhere
between once and three times and the wrong values end up being stored in
ArrayCollection.
The version I got working is good enough for the time being, but If
anyone can tell what I'm doing wrong in the later example, I would love
to find out so I can understand the SDK better.
Thanks for your help Alex!
Keith