Simon_Weaver
Simon_Weaver

Reputation: 145880

Cannot get itemDoubleClick event to work in Flex (even with doubleClickEnabled=true)

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

Upvotes: 1

Views: 6031

Answers (2)

firstboy
firstboy

Reputation: 11

Before I use the propety doubleClickEnabled, my itemDoubleClick doesn't work, but when I set doubleClickEnabled=true, it work good, no problem.

Upvotes: 1

Ross Henderson
Ross Henderson

Reputation: 1779

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>

Upvotes: 1

Related Questions