Spark DataGrid在keyDown上选择了单元格编辑



我使用的是spark DataGrid。我想模仿Excel Behavior=当选择单个单元格,用户开始在键盘上键入时,所选单元格将进入编辑模式。我是通过在1st keyDown事件上启动gridItemEditorSession来完成的,但我遇到的问题是,在启动gridItemEditorSession后,单元格中的值被选中,因此2nd keyDown删除了1st keyDown字符;/

以下是演示:只需选择任何单元格并开始打字:

<?xml version="1.0" encoding="utf-8"?>
<s:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark">
    <fx:Script>
        <![CDATA[
            private function onKeyDown():void
            {
                trace(dataGrid.grid.anchorRowIndex)
                trace(dataGrid.grid.caretRowIndex)
                dataGrid.startItemEditorSession(dataGrid.grid.anchorRowIndex, dataGrid.grid.anchorColumnIndex)
            }
            private function onGridRollOver():void
            {
            }
        ]]>
    </fx:Script>
    <s:DataGrid id="dataGrid" requestedRowCount="5" width="350" editable="true"
        height="300" selectionMode="multipleCells" keyDown="onKeyDown()"
        gridRollOver="onGridRollOver()">
        <s:ArrayCollection>
                <s:DataItem key="1000" name="Abrasive" price="100.11" call="false"/>
                <s:DataItem key="1001" name="Brush" price="110.01" call="true"/>
                <s:DataItem key="1002" name="Clamp" price="120.02" call="false"/>
                <s:DataItem key="1003" name="Drill" price="130.03" call="true"/>
                <s:DataItem key="1004" name="Epoxy" price="140.04" call="false"/>
                <s:DataItem key="1005" name="File" price="150.05" call="true"/>
                <s:DataItem key="1006" name="Gouge" price="160.06" call="false"/>
                <s:DataItem key="1007" name="Hook" price="170.07" call="true"/>
                <s:DataItem key="1008" name="Ink" price="180.08" call="false"/>
                <s:DataItem key="1009" name="Jack" price="190.09" call="true"/>             
            </s:ArrayCollection>
        </s:DataGrid>
</s:Application>

我不太熟悉Flex,但听起来你有一个字符串处理问题。类似的东西

private function handleKeydown(e:KeyboardEvent):void
{
    output_txt.text = String.fromCharCode(e.charCode);
}

而不是

private function handleKeydown(e:KeyboardEvent):void
{
    output_txt.appendText(String.fromCharCode(e.charCode));
}

请确保将输入附加到文本中,而不是替换。

最新更新