Preventing Row Highlight in a Flex DataGrid

UPDATE Post changed with a correct revised method due to previous approach unsettling the custom renderer.

I had a little gripe today with preventing rows displaying the default row highlight within a Flex DataGrid. Rollover highlight is easy to prevent using useRollOver=”false” but ditching the selection highlight is a little trickier. I achieved removing the highlight by overriding the drawSelectionIndicator() method in my custom grid class and passing 0 for the height param. See code below:

1
2
3
4
5
6
7
8
9
/** 
  * Override the below method:
  * (1) Stop the row highlight selection.
  */
 override protected function drawSelectionIndicator( indicator:Sprite, x:Number, y:Number, width:Number,
                                                              height:Number, color:uint, itemRenderer:IListItemRenderer):void
{
  super.drawSelectionIndicator(indicator, x, y, unscaledWidth - viewMetrics.left - viewMetrics.right, 0, color, itemRenderer);
}

Comments