DataGrid
1 <?xml version="1.0" encoding="utf-8"?> 2 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 3 xmlns:s="library://ns.adobe.com/flex/spark" 4 xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> 5 <fx:Declarations> 6 <!-- Place non-visual elements (e.g., services, value objects) here --> 7 </fx:Declarations> 8 9 <fx:Script> 10 <![CDATA[ 11 import mx.rpc.events.ResultEvent; 12 private function createRow(event:MouseEvent):void 13 { 14 var gridRow:GridRow = new GridRow(); 15 16 var gridItem0:GridItem = new GridItem(); 17 var gridItem1:GridItem = new GridItem(); 18 var gridItem2:GridItem = new GridItem(); 19 var gridItem3:GridItem = new GridItem(); 20 var gridItem4:GridItem = new GridItem(); 21 22 var num_text:TextInput = new TextInput(); 23 var username_text:TextInput = new TextInput(); 24 var age_text:TextInput = new TextInput(); 25 var birthday_text:TextInput = new TextInput(); 26 var delButton:Button = new Button(); 27 28 gridItem0.addElement(num_text); 29 gridItem1.addElement(username_text); 30 gridItem2.addElement(age_text); 31 gridItem3.addElement(birthday_text); 32 gridItem4.addElement(delButton); 33 delButton.label="删除"; 34 35 gridRow.addElement(gridItem0); 36 gridRow.addElement(gridItem1); 37 gridRow.addElement(gridItem2); 38 gridRow.addElement(gridItem3); 39 gridRow.addElement(gridItem4); 40 41 delButton.addEventListener(MouseEvent.CLICK, onDelButtonClickHandler); 42 43 this.addUserDataGrid.addElement(gridRow); 44 45 } 46 47 private function onDelButtonClickHandler(event:MouseEvent):void 48 { 49 this.addUserDataGrid.removeChild(GridRow(GridItem(Button(event.target).parent).parent));//添加监听 50 } 51 ]]> 52 </fx:Script> 53 <mx:Grid width="100%" id="addUserDataGrid" top="5" bottom="5"> 54 <mx:GridRow> 55 <mx:GridItem> 56 <s:Label text="id"/> 57 </mx:GridItem> 58 <mx:GridItem> 59 <s:Label text="username"/> 60 </mx:GridItem> 61 <mx:GridItem> 62 <s:Label text="age"/> 63 </mx:GridItem> 64 <mx:GridItem> 65 <s:Label text="birthday"/> 66 </mx:GridItem> 67 <mx:GridItem> 68 <s:Label text="caozuo"/> 69 </mx:GridItem> 70 </mx:GridRow> 71 <mx:GridRow> 72 <mx:GridItem> 73 <s:TextInput id="num"/> 74 </mx:GridItem> 75 <mx:GridItem> 76 <s:TextInput id="username"/> 77 </mx:GridItem> 78 <mx:GridItem> 79 <s:TextInput id="age"/> 80 </mx:GridItem> 81 <mx:GridItem> 82 <mx:DateField id="birthday"/> 83 </mx:GridItem> 84 <mx:GridItem> 85 <s:Button label="add" click="createRow(event)"/> 86 </mx:GridItem> 87 </mx:GridRow> 88 </mx:Grid> 89 </s:Application>