Flex Datagrid编辑事件

时间:2012-06-12 04:30:36

标签: actionscript-3 flex datagrid flex3

在我的flex应用程序中使用带有5列的数据网格...其中3个是可编辑的...如果我向网格添加项目,当我按Enter键时,光标位置在网格中从右向左移动在Datagrid单元格..通过重复更多的项目...它的工作....添加20项后,光标...垂直可移动的单元格移动...即:当我点击进入时,从上到下移动...   怎么解决这个?

继承我的网格代码

<mx:AdvancedDataGrid id="Do" dataProvider="{GrdPrvider}" keyDown="Do_keyDownHandler(event)" 
                             headerHeight="22" resizeEffect="resize" editable="true" sortExpertMode="true" lockedColumnCount="3" horizontalScrollPolicy="auto" verticalScrollPolicy="auto" width="95%" height="160" x="0" y="10"><mx:columns>
                <mx:AdvancedDataGridColumn headerText="#" editable="false" width="40" dataField="SerialNo" sortCompareFunction="SiNoCompare" />
                <mx:AdvancedDataGridColumn headerText="Desc" editable="false" labelFunction="dgLableFunction" sortCompareFunction="sortableDesc" width="250"/>
                <mx:AdvancedDataGridColumn headerText="Fos" sortable="false" editable="true" width="40"> <mx:AdvancedDataGridColumn headerText="gos" sortable="false" editable="true" width="40"> 

对于按键事件,功能如下..

protected function Do_keyDownHandler(event:KeyboardEvent):void
        {


            if (event.keyCode == Keyboard.ENTER)
            {
                if(Do.columns[colIdx].editable && event.currentTarget.selectedIndex <= Do.columnCount)
                {

                    var cols:ArrayCollection = new ArrayCollection(Do.columns);
                    var nxtGet:Boolean = false;
                    for(var i:String in cols)
                    {
                        if((int(i) > colIdx) && Do.columns[i].editable && (!nxtGet))
                        {
                            colIdx = int(i);                
                            nxtGet = true;
                        }
                    }
                    if(nxtGet)
                    {
                        Do.editedItemPosition ={rowIndex: event.currentTarget.selectedIndex, columnIndex: colIdx};
                        event.preventDefault();                 
                        Do.dataProvider.refresh();  
                    }
                    else
                    {
                        for(var r:String in  Do.columns)
                        {
                            if(Do.columns[r].headerText == "Fos")
                            {
                                colIdx = parseInt(r);
                            }
                        }               
                        Do.editedItemPosition ={rowIndex: event.currentTarget.selectedIndex+1, columnIndex: colIdx};
                        event.preventDefault();                 
                        Do.dataProvider.refresh();  
                    }

                } 

            }
        }

0 个答案:

没有答案