1

在我的 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();  
                    }

                } 

            }
        }
4

0 回答 0