DataGrid doesn't use CLICK, it uses MOUSE_DOWN/MOUSE_UP ________________________________
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of bsensale Sent: Monday, May 19, 2008 4:56 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Manually dispatching MouseEvents on DataGrid rows I'm trying to manually dispatch a mouse event on rows in a datagrid, and am running into some strange behavior. Basically, if I trace the Mouse Click on a datagrid row, I can desconstruct the mouse event. If I dispatch the event manually, the deconstructed event looks the same, but the grid selection never happens. Does anyone know of a way to actually get a manually dispatched MouseClick to select an item in a dataGrid row? I know about using selectedIndices and change events, but need to actually get Click events. I saw that the MouseEvent when clicking on the grid is one a DataGridItemRenderer. I used the DataGrid.indexToItemRenderer() to get a handle on the row. The MXML below shows this behavior. If you click on a row in the datagrid, it is selected, and the mouse event is taken apart and shown in the text area. If you click the button, the same event is fired, but the row isn't selected: Sample of the output: Click on targetClickEvent0.myDataGrid.ListBaseContentHolder7.DataGridItemRender er33 event.altKey: false event.bubbles: true event.buttonDown: false event.cancelable: false event.ctrlKey: false event.currentTarget: ClickEvent0 event.delta: 0 event.eventPhase: 3 event.localX: 396 event.localY: 2 event.relObj: null event.shiftKey: false event.stageX: 397 event.stageY: 27 event.type: click ============================================= Click on targetClickEvent0.myDataGrid.ListBaseContentHolder7.DataGridItemRender er33 event.altKey: false event.bubbles: true event.buttonDown: false event.cancelable: false event.ctrlKey: false event.currentTarget: ClickEvent0 event.delta: 0 event.eventPhase: 3 event.localX: 139 event.localY: 7 event.relObj: null event.shiftKey: false event.stageX: 140 event.stageY: 32 event.type: click ============================================= Click on targetClickEvent0.myButton event.altKey: false event.bubbles: true event.buttonDown: false event.cancelable: false event.ctrlKey: false event.currentTarget: ClickEvent0 event.delta: 0 event.eventPhase: 3 event.localX: 107 event.localY: 5 event.relObj: null event.shiftKey: false event.stageX: 713 event.stageY: 242 event.type: click ============================================= <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> " layout="absolute" creationComplete="onCreationComplete()"> <mx:Script> <![CDATA[ private function onCreationComplete():void { addEventListener(MouseEvent.CLICK, onMouseClick); } private function onMouseClick(event:MouseEvent):void { var text:String = myTextArea.text; text += "\rClick on target" + event.target; text += "\revent.altKey: " + event.altKey; text += "\revent.bubbles: " + event.bubbles; text += "\revent.buttonDown: " + event.buttonDown; text += "\revent.cancelable: " + event.cancelable; text += "\revent.ctrlKey: " + event.ctrlKey; text += "\revent.currentTarget: " + event.currentTarget; text += "\revent.delta: " + event.delta; text += "\revent.eventPhase: " + event.eventPhase; text += "\revent.localX: " + event.localX; text += "\revent.localY: " + event.localY; text += "\revent.relObj: " + event.relatedObject; text += "\revent.shiftKey: " + event.shiftKey; text += "\revent.stageX: " + event.stageX; text += "\revent.stageY: " + event.stageY; text += "\revent.type: " + event.type; text += "\r============================================="; trace(text); myTextArea.text = text; myTextArea.verticalScrollPosition = myTextArea.maxVerticalScrollPosition; } private function onMyButtonClick():void { var mouse:MouseEvent = new MouseEvent (MouseEvent.CLICK, true, false, 139, 7, null); myDataGrid.indexToItemRenderer(0).dispatchEvent (mouse); } ]]> </mx:Script> <!--<mx:VBox height="100%" horizontalCenter="238" verticalCenter="17">--> <mx:DataGrid y="0" width="100%" height="217" id="myDataGrid" horizontalCenter="0"> <mx:Object FName="Brian" LName="Sensale"/> <mx:Object FName="Al" LName="Manning"/> <mx:columns> <mx:DataGridColumn headerText="First" dataField="FName"/> <mx:DataGridColumn headerText="Last" dataField="LName"/> </mx:columns> </mx:DataGrid> <mx:Button id="myButton" y="237" label="Click to dispatch Mouse Event" horizontalCenter="64" click="onMyButtonClick()"/> <mx:TextArea id="myTextArea" y="279" width="100%" height="479" horizontalCenter="0"/> <!--</mx:VBox>--> </mx:Application>