<?xml version="1.0" encoding="utf-8"?>
< s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="application1_creationCompleteHandler(event)" >
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;
import mx.events.FlexEvent;
[Bindable]
private var ac:ArrayCollection = new ArrayCollection();
private var arr:Array = new Array();
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
arr.push({first:"aaaaa", second:"bbbbbb"});
arr.push({first:"ccccc", second:"dddddd"});
arr.push({first:"eeeee", second:"ffffff"});
arr.push({first:"ggggg", second:"iiiiii"});
arr.push({first:"aaaaa", second:"bbbbbb"});
arr.push({first:"ccccc", second:"dddddd"});
arr.push({first:"eeeee", second:"ffffff"});
arr.push({first:"ggggg", second:"iiiiii"});
ac.source = arr;
dg.dataProvider = ac;
}
protected function button1_clickHandler(event:MouseEvent):void
{
//var arr2:Array = new Array();
arr[0]={first:"2222", second:"bbbbbb"};
arr[1]={first:"333", second:"dddddd"};
arr[2]={first:"444", second:"ffffff"};
arr[3]={first:"5555", second:"iiiiii"};
ac.refresh();
//또는 dg.dataProvider.dispatchEvent(new CollectionEvent(CollectionEvent.COLLECTION_CHANGE));
}
]]>
</fx:Script>
<mx:DataGrid id="dg" >
<mx:columns>
<mx:DataGridColumn dataField="first" />
<mx:DataGridColumn dataField="second"/>
</mx:columns>
</mx:DataGrid>
<mx:Button id="addBtn" y="200" label="add" click="button1_clickHandler(event)"/>
< /s:Application>