Apache Flex 如何 在 spark 数据 网格 中 获取 itemDoubleClick 事件 ?

bfrts1fy  于 2022-11-21  发布在  Apache
关注(0)|答案(3)|浏览(172)

最近我正在使用Spark DataGrid。之前我使用AdvancedDataGrid。在此期间我捕获了itemDoubleClick事件。但我无法在SparkdataGrid中找到此类事件。
所以我想在DataGrid的单行上捕获双击事件。
有些人告诉我,我必须使用我的自定义ItemRenderer来做到这一点。但是有没有什么方法可以在Spark DataGrid中捕获itemDoubleClick事件而不创建自定义的ItemRenderer???

qybjjes1

qybjjes11#

在动作脚本中:

myDataGrid.doubleClickEnabled = true;
myDataGrid.addEventListener(GridEvent.GRID_DOUBLE_CLICK, handleGridDoubleClick);

private function handleGridDoubleClick(event:GridEvent):void {
    trace(event.rowIndex, event.columIndex);
    trace(event.column, event.item);
}

或者在MXML中:

<s:DataGrid doubleClickEnabled="true" 
            doubleClick="handleGridDoubleClick(event)" />

默认情况下,“doubleClickEnabled”为“false”,因此必须将其显式设置为“true”

bqujaahr

bqujaahr2#

您不需要自定义ItemRenderer。只需执行以下操作:

<?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[
            import spark.events.GridEvent;

            private var lastColumnIndex:int = -1;
            private var lastRowIndex:int = -1;

            // set this to change the double click time   
            //mx_internal::event.grid.DOUBLE_CLICK_TIME = 480;  // ms

            protected function dataGrid_gridClickHandler(event:GridEvent):void
            {               
                trace("click on this cell", event.rowIndex, event.columnIndex);

                lastRowIndex = event.rowIndex;
                lastColumnIndex = event.columnIndex;
            }

            protected function dataGrid_gridDoubleClickHandler(event:GridEvent):void
            {
               if (event.rowIndex == lastRowIndex && event.columnIndex == lastColumnIndex)
                   trace("a real double click on this cell", event.rowIndex, event.columnIndex);
               else
                   trace("this is a gridClick on another cell", event.rowIndex, event.columnIndex);

               lastRowIndex = event.rowIndex;
               lastColumnIndex = event.columnIndex;
            }

        ]]>
    </fx:Script>

        <s:DataGrid id="dataGrid" requestedRowCount="5" verticalCenter="0" horizontalCenter="0"
                     doubleClickEnabled="true"
                      gridClick="dataGrid_gridClickHandler(event)"
                      gridDoubleClick="dataGrid_gridDoubleClickHandler(event)">
            <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>
r1wp621o

r1wp621o3#

设置selectionMode=“singleRow”,或者根据需要设置其他值,并使用gridDoubleClick事件

相关问题