删除dateGrid数据?

时间:2013-06-12 09:37:06

标签: actionscript flex4

如何在单击按钮(网格外部)时删除数据网格数据。

[Bindable]                 
        private var ac:ArrayCollection=new ArrayCollection([{artist: "John", album:"AAA", price:"100.01", selected: false}, 
            {artist: "Jai", album:"BBB", price:"101.01", selected: false}, {artist: "Jack", album:"CCC", price:"110.01", selected: false}]);
        <s:DataGrid id="myDG" width="50%" height="50%" dataProvider="{ac}"
        > 

    <s:columns>
        <s:ArrayCollection>

            <s:GridColumn dataField="artist" headerText="ARTIST"/>
            <s:GridColumn dataField="album" headerText="ALBUM"/>
            <s:GridColumn dataField="price" headerText="PRICE" >
                <s:itemEditor> 
                    <fx:Component> 
                        <s:ComboBoxGridItemEditor> 
                            <s:dataProvider>
                                <s:ArrayList>
                                    <fx:String>100</fx:String>
                                    <fx:String>200</fx:String>
                                    <fx:String>300</fx:String>
                                </s:ArrayList>
                            </s:dataProvider>
                        </s:ComboBoxGridItemEditor> 
                    </fx:Component> 
                </s:itemEditor>    
            </s:GridColumn>

        </s:ArrayCollection>
    </s:columns>
</s:DataGrid> 

我需要在grid.data之外有一个按钮来自dataprovider

2 个答案:

答案 0 :(得分:1)

private function button1_clickHandler(event:MouseEvent):void{

ac.removeItemAt(myDG.selectedIndex);

}

答案 1 :(得分:0)

         public function deletefromgrid():void {
            if (dg.selectedIndex >= 0) { 
                ac.removeItemAt(dg.selectedIndex); 
        }
        }