博客园站长
这是人类成长进步中记录的每一时刻

<?xml version="1.0" encoding="utf-8"?>
<mstr:MstrApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:mstr="http://web.microstrategy.com/visframe" xmlDataFile="GetcolumnData.xml" layout="absolute">
<fx:Script>
<![CDATA[
import mx.controls.*;
import mx.events.ListEvent;
import mx.controls.dataGridClasses.*;


[Bindable]//原始数据
public var dataArr:Array = [{id:1,name:"苹果",count:100},
{id:2,name:"西瓜",count:200},
{id:3,name:"水蜜桃",count:50}]

private function addItem():void{
dataArr.push({id:uiId.value,name:uiName.text,count:uiCount.value})
DataGrid2.dataProvider = dataArr
}
private function delItem():void{
dataArr.pop();
DataGrid2.dataProvider = dataArr
}
private function itemClick(e:ListEvent):void{
var txt:String = "表头为: "+(e.target as DataGrid).columns[e.columnIndex].headerText+"\n"
txt+="选中第 "+e.columnIndex+" 列\n"
txt+="选中第 "+e.rowIndex+" 行\n"
txt+="选中的行的数据为:\n"
var dat:Object = (e.target as DataGrid).selectedItem
for(var i:* in dat){
txt+=" "+i+":"+dat[i]+"\n"
}
txt+="选中的单元可格的数据为 "+(e.target as DataGrid).selectedItem[(e.target as DataGrid).columns[e.columnIndex].dataField]+" \n"
Alert.show(txt)
}
]]>
</fx:Script>

<mx:DataGrid id="DataGrid2" itemClick="itemClick(event)" dataProvider="{dataArr}" width="430" y="10" x="10" height="208">
<mx:columns>
<mx:DataGridColumn headerText="序号" dataField="id"/>
<mx:DataGridColumn headerText="名称" dataField="name"/>
<mx:DataGridColumn headerText="数量" dataField="count" editorDataField="value"/>
</mx:columns>
</mx:DataGrid>
<mx:NumericStepper id="uiId" x="10" y="241" width="150"/>
<mx:TextInput id="uiName" x="10" y="288" width="150"/>
<mx:NumericStepper id="uiCount" x="10" y="335" width="150"/>
<mx:Label x="10" y="224" text="序号:"/>
<mx:Label x="10" y="271" text="名称:"/>
<mx:Label x="10" y="318" text="数量:"/>
<mx:Button click="addItem()" x="10" y="368" label="添加" width="150"/>
<mx:Button click="delItem()" x="290" y="368" label="删除最后一个" width="150"/>

</mstr:MstrApplication>

 

 

转载何处忘记了``

posted on 2012-03-19 16:16  dm3344  阅读(248)  评论(0编辑  收藏  举报