How to remove the highlight/selection on AdvancedDataGrid
This page describes how to override the drawHighlightIndicator/drawSelectionIndicators methods for the header of a DataGrid, but an AdvancedDataGrid does not have "hea开发者_如何转开发derClass" in mx_internal. It instead has an headerRenderer.
How can I remove those blasted highlights over an AdvancedDataGrid in Flex 3?
Sorry to post a different answer but I don't have enough 'points' to make a direct comment on this. Today I had run into exact same issue and found this post very helpful.
Correct me if I'm wrong but I think one line is missing in the mouseDownHandler which prevents AdvancedDataGrid from properly sorting the data (if data sorting is enabled):
override protected function mouseDownHandler(event:MouseEvent):void
{
super.mouseDownHandler(event);
var s:Sprite = Sprite(
selectionLayer.getChildByName("headerSelection"));
if(s) s.graphics.clear();
}
Though it may be useful.
The graphics calls that draw that are in AdvancedDataGridBaseEx.as from lines 5468-5471:
var g:Graphics = s.graphics;
g.clear();
g.beginFill(getStyle("rollOverColor")); //all I really wanted was to decrease the alpha here :(
g.drawRect(0, 0, w, h - 0.5);
g.endFill();
To get rid of this you can do this in an class that extends AdvancedDataGrid:
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import mx.controls.AdvancedDataGrid;
public class AdvancedDataGridMinusHighlights extends AdvancedDataGrid
{
public function AdvancedDataGridMinusHighlights()
{
super();
}
override protected function mouseOverHandler(event:MouseEvent):void
{
super.mouseOverHandler(event);
var s:Sprite = Sprite(
selectionLayer.getChildByName("headerSelection"));
if(s) s.graphics.clear();
}
override protected function mouseDownHandler(event:MouseEvent):void
{
super.mouseDownHandler(event);
var s:Sprite = Sprite(
selectionLayer.getChildByName("headerSelection"));
if(s) s.graphics.clear();
}
}
}
Although that is an extremely inelegant solution since all it does is clear what has already been drawn. Because there's so much other crap in the mouse handlers in AdvancedDataGridBaseEx you won't easily be able to customize the appearance of the header.
A slightly more elegant (hack) solution is to copy the full source of AdvancedDataGridBaseEx into the mx.controls package (a hack I'm sure many of you are aware of and equally aware of the consequences).
精彩评论