suganya's Blog

Just another WordPress.com weblog

Binding to a selected row

<mx:DataGrid id="dg" width="500" height="150" dataProvider="{myAC}">
 <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:Label text="The selected person is {dg.selectedItem.name}
   ({dg.selectedItem.email})" fontSize="16"/>

June 9, 2009 Posted by | List | Leave a Comment

Passing data to a function

Handling a user interaction and passing only data to a function:

<mx:DataGrid id="dg" width="500" height="150" dataProvider="{myAC}"
         itemClick="handleClick(event.currentTarget.selectedItem)">
  <mx:columns>
   <mx:DataGridColumn dataField="name"
                headerText="Contact Name" width="300" />
    <mx:DataGridColumn dataField="email" headerText="E-Mail" width="200"/>
  </mx:columns>
</mx:DataGrid>

When you click an item, your function  is invoked along with a 

reference to the item clicked. This lets you access the  various

 properties of the object:
 public function handleClick(data:Object):void
{
  Alert.show("Name:" + data.name + ",Email:" + data.email);
}

June 9, 2009 Posted by | List | Leave a Comment

Passing the event to a function

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>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.ListEvent;
import mx.controls.Alert;
public var myAC:ArrayCollection  = new ArrayCollection([
{name:"Jon Hirschi", email:"j_hirschi@domain.com"},
{name:"Frank Krul",  email:"f_krul@domain.com"}]);
public function handleClick(evt:ListEvent):void{
Alert.show(“You clicked on row:” + evt.rowIndex + ” and 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>

June 9, 2009 Posted by | List | Leave a Comment

   

Follow

Get every new post delivered to your Inbox.