20 August 2008

FLEX: add arrays to ArrayCollection to use as DataProvider

Web Service call return in Flex two arrays (a_RowColumn and a_RowColumnProperties) , to use these arrays as source in DataGrid we can put them in ArrayCollection and then use this ArrayCollection as DataProvider for DataGrid.

Code example:

[Bindable]
private var arrCol:ArrayCollection = new ArrayCollection();

arrCol.removeAll();
var newRow : Object;
var i:int;
for (i = 0; i < a_RowColumn.length; i++)
{
newRow = new Object();
newRow.col1 = a_RowColumn[i];
newRow.col2 = a_RowColumnProperties[i];

arrCol.addItem(newRow);
}

dg_FieldList.dataProvider=arrCol;


<mx:DataGrid x="47" y="95" width="90%" height="90%" id="dg_FieldList">
<mx:columns>
<mx:DataGridColumn headerText="Field-Number" dataField="col1"/>
<mx:DataGridColumn headerText="Field-Description" dataField="col2"/>
</mx:columns>
</mx:DataGrid>

Is there any other way to use arrays from Web Service response as DataProvider for DataGrid?

No comments: