00.Flex,Flash,ActionScript2013. 4. 24. 19:29
반응형

출처 : http://eflex.tistory.com/entry/DataGrid-%EC%A0%84%EC%B2%B4-%EB%8B%A4%EC%8B%9C-%EA%B7%B8%EB%A6%AC%EC%A7%80-%EC%95%8A%EA%B3%A0-%EB%8D%B0%EC%9D%B4%ED%84%B0%EB%A7%8C-%EA%B0%B1%EC%8B%A0%ED%95%98%EA%B8%B0

 

<?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>

Posted by 1010