Handling a user interaction by passing the event object to a function
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.collections.ArrayCollection;
import mx.events.ListEvent;
import mx.controls.Alert;
public var myAC:ArrayCollection = new ArrayCollection([
{name:"A", email:"j@domain.com"},
{name:"B", email:"f@domain.com"}]);
public function handleClick(evt:ListEvent):void
{
Alert.show(evt.rowIndex + " / col:" + evt.columnIndex + "." + "Which is for " + evt.currentTarget.selectedItem.name);
}
</mx:Script>
<mx:DataGrid id="dg" width="500" height="150" dataProvider="{myAC}"
itemClick="handleClick(event)">
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="Contact Name" width="300" />
<mx:DataGridColumn dataField="email" headerText="E-Mail" width="200" />
</mx:columns>
</mx:DataGrid>
</mx:Application>
Related examples in the same category