Skip navigation
Currently Being Moderated

How do I get itemDoubleClick event in spark DataGrid ???

Mar 6, 2012 11:15 PM

Tags: #air #as3 #flex #spark #datagrid #flex4 #flex4.5 #4.6

Hello Everyone,

 

Recently I am working with Spark DataGrid.

Before I was using AdvancedDataGrid. In that I was capturing itemDoubleClick event.

But I am not able to find such a event in SparkdataGrid.

 

So I want to capture double click event on single row of DataGrid.

 

Some people told that, I have to use my custom ItemRenderer to do that.

But is there any way to capture itemDoubleClick event in Spark DataGrid without creating custom ItemRenderer ???

 
Replies
  • Currently Being Moderated
    Mar 6, 2012 11:19 PM   in reply to Mitul Golakiya

    I think, just user gridDoubleClick  then check which row and column in the handler

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 8, 2012 6:43 AM   in reply to Mitul Golakiya

    You are correct.  I looked a the code and the comment says it dispatches a double click if the 2nd click is within the  DOUBLE_CLICK_TIME even if the first click was on another cell.

     

    This code figures out if the double-click is a true double-click.

     

    <?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>

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 3, 2014 5:18 AM   in reply to Carol L. Frampton

    DataGrid now has a property called doubleClickMode (since 4.5 according to the comments). Set that to 'cell' or 'row' to ensure correct behaviour. Oddly, when this value is set as an MXML property, it causes an RTE, as the property doesn't seem to be using the invalidation pattern, but doing it this way will work:

     

    <s:DataGrid id="resultsGrid" creationComplete="resultsGrid.doubleClickMode = 'row'"/>

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points