Flex DataGrid可编辑对象实现Enter跳转
來源:http://blog.sina.com.cn/s/blog_5ed17a730100vrja.html
在Flex DataGrid中實現(xiàn)點擊Enter鍵可編輯對象跳轉
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="100%"
????height="100%" creationComplete="init()">
????<mx:DataGrid id="dg" dataProvider="{ac}" height="232" editable="true">
????????<mx:columns>
????????????<mx:DataGridColumn headerText="姓名" dataField="name"/>
????????????<mx:DataGridColumn headerText="年齡" dataField="age"/>
????????</mx:columns>
????</mx:DataGrid>
????<mx:ArrayCollection id="ac">
????????<mx:Object name="111" age="11"/>
????????<mx:Object name="222" age="22"/>
????????<mx:Object name="333" age="33"/>
????????<mx:Object name="444" age="44"/>
????????<mx:Object name="555" age="55"/>
????????<mx:Object name="666" age="66"/>
????</mx:ArrayCollection>
????<mx:Script>
????????<![CDATA[
????????????import mx.core.EdgeMetrics;
????????????import mx.events.DataGridEvent;
????????????import mx.events.ListEvent;
????????????
????????????private function init():void {
????????????????addEventListener(KeyboardEvent.KEY_DOWN, enterKHandler);
????????????}
????????????
????????????private function enterKHandler(evt:KeyboardEvent):void {
????????????????if(dg.editedItemPosition == null) {
????????????????????return;
????????????????}
????????????????
????????????????var editpos:Object = dg.editedItemPosition;
????????????????
????????????????if(evt.keyCode == Keyboard.ENTER){
????????????????????if(editpos.rowIndex == dg.dataProvider.length-1) {
????????????????????????if(editpos.columnIndex < dg.columnCount-1) {
????????????????????????????editpos.columnIndex ++;
????????????????????????????dg.editedItemPosition = editpos;
????????????????????????} else if(editpos.columnIndex == dg.columnCount-1) {
????????????????????????????var obj:Object = {name:"777", age:"7"};
????????????????????????????ac.addItem(obj);
????????????????????????????
????????????????????????????editpos.rowIndex ++;
????????????????????????????editpos.columnIndex = 0;
????????????????????????????dg.editedItemPosition = editpos;
????????????????????????}
????????????????????} else if(editpos.rowIndex < dg.dataProvider.length-1) {
????????????????????????if(editpos.columnIndex < dg.columnCount-1) {
????????????????????????????editpos.columnIndex ++;
????????????????????????????dg.editedItemPosition = editpos;
????????????????????????} else {
????????????????????????????editpos.rowIndex ++;
????????????????????????????editpos.columnIndex = 0;
????????????????????????????dg.editedItemPosition = editpos;
????????????????????????}
????????????????????}
????????????????}
????????????}
????????????
????????]]>
????</mx:Script>
</mx:Application>
轉載于:https://www.cnblogs.com/6303c/p/3139496.html
總結
以上是生活随笔為你收集整理的Flex DataGrid可编辑对象实现Enter跳转的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 环球网校直播课件和精讲班哪个好?
- 下一篇: 单号,尚品类目,数量,三个要素全部一样时