Random techie babbling...

Change vs Click in the Flex 3 DataGrid

(related to a tip I found, but for Flex 3 and my own memory…)

In Flex3 you can be notified of changes to selections in your datagrid from using listeners to either the ‘click’ or ‘change’ events, the difference being that if you only listen for click events you won’t be notified when the user navigates or selects with the keyboard (obvious, but confused me for a bit). This seems a shame given Flex’s pretty good handling of keyboard navigation, so unless you only want mouse click events use a ‘change’ handler as standard.

Using a Click Handler:

<mx:DataGrid id="DG1" click="clickHandler(event)"/>
<mx:Script>
  public function clickHandler(event:MouseEvent):void
  {
      someControl.text = event.currentTarget.selectedItem.someDataField;
  } 
</mx:Script>

Using a Change Handler:

<mx:DataGrid id="DG2" change="changeHandler(event)"/>
<mx:Script>
  public function changeHandler(event:Event):void
  {
      someControl.text = event.target.selectedItem.someDataField;
  } 
</mx:Script>

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

2 Comments

Got something to say? Feel free, I want to hear from you! Leave a Comment

  1. Leonardo says:

    I found this comment in the best moment. Thank you so much!

  2. Thak’s you helped me.

Leave a Comment

Let us know your thoughts on this post but remember to place nicely folks!