Lieven Cardoen
Lieven Cardoen

Reputation: 25969

Bind dataprovider DataGrid to an Array

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; }
    ...

Upvotes: 1

Views: 4197

Answers (1)

dirkgently
dirkgently

Reputation: 111280

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.

Upvotes: 3

Related Questions