views:

2010

answers:

3

I am trying to do a simple datagrid in Flex with a doubleclick event, but I cannot get itemDoubleClick to fire:

<mx:DataGrid id="gridReportConversions" height="100%" width="100%" mouseEnabled="true" doubleClickEnabled="true" itemDoubleClick="refererRowDoubleClicked(event)">
        <mx:columns>
         <mx:DataGridColumn width="75" dataField="qty" headerText="Qty" />
         <mx:DataGridColumn dataField="referer" headerText="URL" />
        </mx:columns>
       </mx:DataGrid>

If I use the itemClicked event then the event is raised just fine. When I search for this problem I find many people saying 'you need to set doubleClickEnabled=true, but I've done that and it still doesn't work.

This control is nested within quite a few levels of VBox and other containers. Surely I dont need to set doubleClickEnabled on each of those containers do I?

Just to clarify how I tested this - I have an alert box in my refererRowDoubleClicked event handler and it never gets shown when I use itemDoubleClick

A: 

Simon,

I was able to get your code to work, no problem. Wrapped it up in several layers of containers that didn't have doubleClickEnabled set to true, to see if that was an issue, but it doesn't seem to be.

I'm wondering if one of the parents is causing a problem somehow. Would it be possible for you to post a larger section of the code?

Here is what I ran to test this with:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

    <mx:Script>
     <![CDATA[
      import mx.controls.Alert;
      import mx.collections.ArrayCollection;

      [Bindable] private var dp:ArrayCollection = new ArrayCollection([{qty:1,referer:'http://google.com'},{qty:25,referer:'http://cnn.com'},{qty:4,referer:'http:stackoverflow.com'}]);



      private function refererRowDoubleClicked(e:Event):void
      {

       var msg:String = "target: " + e.target + "\n\ncurrentTarget: " + e.currentTarget + "\n\nselected item qty: " + gridReportConversions.selectedItem.qty + "\nselected item referer: " + gridReportConversions.selectedItem.referer;
       Alert.show(msg);
      }

     ]]>
    </mx:Script>


    <mx:VBox width="100%" height="100%">  
     <mx:VBox width="100%" height="100%">   
      <mx:Box width="100%" height="100%">
         <mx:Canvas width="100%" height="100%">       
          <mx:DataGrid id="gridReportConversions" height="100%" width="100%" dataProvider="{this.dp}"
           mouseEnabled="true" doubleClickEnabled="true" itemDoubleClick="refererRowDoubleClicked(event)">
                <mx:columns>
                        <mx:DataGridColumn width="75" dataField="qty" headerText="Qty" />
                        <mx:DataGridColumn dataField="referer" headerText="URL" />
                </mx:columns>
          </mx:DataGrid>
       </mx:Canvas>
      </mx:Box>  
     </mx:VBox>
    </mx:VBox>

</mx:Application>
Ross Henderson
thanks a lot for tryin this out. i guess i'll have to take it step by step up the 'container chain' and see if i can get it to work. just wanted to mkae sure initially i wasnt doing somethin stupid
Simon_Weaver
A: 

Thank you for answer.. it works :)

@adriano great! i wish i remember what my original solution was. i'm sure it was something stupid. oh and welcome to stackoverflow - btw you should put things like 'thankyou' messages as comments and not as a new answer - or else people will vote you down. however since you're new you CANT comment (
Simon_Weaver
A: 

Hi,

I'm facing the same issue with a List component, my "itemDoubleClick" being raised only sometimes => how did you make it work please ? Sorry but this does not appear clear to me when you say "it works :)" here above.

With thanks,

Regards.

PS : looking at the end of this post, it seems that there is a limitation... : what do you think ?

http://raghuonflex.wordpress.com/2007/08/10/assigning-different-behaviors-on-click-doubleclick/

unfortunately i haven't done flex work in over a year. the person that said 'it works' wasn't actually me but someone else. i assume he was referring to my accepted answer (shown with green checkmark). did you get to try that solution? im also not sure if the flex framework has fixed this issue since the time of my question
Simon_Weaver