tags:

views:

1202

answers:

1

How do you bind the dataprovider of a DataGrid in Flex to an Array?

This doesn't seem to work:

<mx:DataGrid id="valuesDataGrid" editable="true" width="100%" height="100%" dataProvider="{_metaDataKey.values}">
...

[Bindable]
public class EnumMetaDataKey{

    private var _values:Array = [];

    public function get values():Array { return _values; }
    public function set values(value:Array):void { _values = value; }
    ...
+2  A: 

Use an ArrayCollection instead. Arrays do not lend well to binding. IIRC, this is documented in the Flex 3 help on Binding to functions Objects and Arrays:

Note: When defining a data binding expression that uses an array as the source of a data binding expression, the array should be of type ArrayCollection because the ArrayCollection class dispatches an event when the array or the array elements change to trigger data binding. For example, a call to ArrayCollection.addItem(), ArrayCollection.addItemAt(), ArrayCollection.removeItem(), and ArrayCollection.removeItemAt() all trigger data binding.

dirkgently