开发者

Populate a datagrid from a Loop

I'm just starting to learn flex and AS3

I'm trying to get information into a datagrid that originates from a mathmatical formula. For example if I have 100 and I subtract 5 from it and continue to do so until it reaches 0 so my grid would be something like:

100 | -5

95 | -5

90 | -5

...

...

5 | -5

0

I'm guessing that it needs to do something like this bu开发者_Go百科t can't find any examples of how to impliment something like this:

    var i:Number = 100;
do {
add row to datagrid
i-5;
} while (i < 0);

Thanks Dave


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onCreationComplete()">
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;

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

            private function onCreationComplete():void
            {
                var i:int = 100;

                while(i >= 0) {
                    myDataProvider.addItem({"index" : i});

                    i -= 5;
                }
            }
        ]]>
    </mx:Script>
    <mx:DataGrid dataProvider="{ myDataProvider }" width="100%" height="100%">
        <mx:columns>
            <mx:DataGridColumn dataField="index" headerText="#"/>
        </mx:columns>
    </mx:DataGrid>
</mx:Application>

Also take a look in Flex language reference DataGrid, there is example at the bottom of the page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜