Using roll over color on DataGrid without selection

Problem

You need to have a DataGrid which needs to show a roll over highlight but is not selectable.

Solution

Set selectable to true and override public function isItemSelectable(data:Object) in DataGrid and return false.

Explanation

The mouseOverHandler for DataGrid is implemented in ListBase. The first lines of code are:

  1.     protected function mouseOverHandler(event:MouseEvent):void
  2.     {
  3.         var evt:ListEvent;
  4.        
  5.         if (!enabled || !selectable)
  6.             return;

This presents a problem. The subsequent code tests that the userRollOver style is set and the data is not null. Two solutions present themselves. Either override the mouseOverHandler and remove this check, or set selectable and override other code which looks at selectable.

It turns out that there is a short, public function called isItemSelectable(data:Object) that is trivial to override. It checks selectable for true and data for null. We can simply override it and return false.

Search Great Flex/Flash Sites