I have resolved my problem by overriding drawRowBackgrounds() in
AdvancedDatagrid. This method is called each time I make a vertical
scroll.
public class MyADG extends AdvancedDataGrid
{
public function MYADG()
{
super();
}
override protected function drawRowBackgrounds():void {
super.drawRowBackgrounds();
var rowBGs:Sprite =
Sprite(listContent.getChildByName("rowBGs"));
var lineCol:uint = getStyle("horizontalGridLineColor");
if (!rowBGs)
{
rowBGs = new FlexSprite();
rowBGs.mouseEnabled = false;
rowBGs.name = "rowBGs";
listContent.addChildAt(rowBGs, 0);
}
var g:Graphics=rowBGs.graphics;
var curRow:int = 0;
var n:int = listItems.length;
while (curRow < n)
{
try {
var myObj:Object = listItems[curRow][0].data;
if (myObj.phone == "555-219-2270") {
g.lineStyle(1, 0x00ff00);
} else {
g.lineStyle(1, lineCol);
}
g.moveTo(0,rowInfo[curRow].y+1);
g.lineTo(width,rowInfo[curRow].y+1);
} catch (e:Error) {
trace(e.getStackTrace());
}
curRow++;
}
while (rowBGs.numChildren > 0)
{
rowBGs.removeChildAt(rowBGs.numChildren - 1);
}
}
}
Sophany
--- In [email protected], "Pun Sophany" <[EMAIL PROTECTED]> wrote:
>
> Hello,
> I want to draw horizontal separators between rows with different line
> colors depending on the row data.
> I tried to use optimized item renderers but the performance was still
> too slow during vertical scrolling.
> I also tried to extend AdvancedDatagridItemRenderer and set border at
> true. But I couldn't choose border sides and I only want a border on
the
> bottom side.
> Next I attempted to override the drawHorizontalLine method from
> AdvancedDatagrid class:
> drawHorizontalLine is called from drawHorizontalSeparators().
>
> override protected function drawHorizontalLine(s:Sprite, rowIndex:int,
> color:uint, y:Number):void {
> if(indexToItemRenderer(rowIndex) != null) {
> var myObj:Object = indexToItemRenderer(rowIndex).data;
> var g:Graphics = s.graphics;
> if (myObj.name == "John") {
> g.lineStyle(1, 0x0000ff);
> g.moveTo(0, y);
> g.lineTo(width, y);
> } else {
> g.lineStyle(1, 0x000000);
> g.moveTo(0, y);
> g.lineTo(width, y);
> }
> }
> }
>
> The first display is correct. But after a vertical scroll, horizontal
> lines keep their position and are not redrawn no matter what the row
is,
> because drawHorizontalSeparators() is not recalled.
> So I tried to call drawHorizontalSeparators() on Scroll event:
failure,
> separator lines on top and bottom rows disappear during the vertical
> scroll.
>
> Is there a way I can draw different horizontal separators depending on
> data without using item renderers?
>
> Thanks in advance.
>
> Sophany
>