How to automate vertical scrolling in Flex AdvancedDataGrid when dragging item below bottom of visible rows?

StackOverflow https://stackoverflow.com/questions/2913420

문제

I have an AdvancedDataGrid with XML dataProvider. Drag and drop in enabled, and works within the visible rows of the ADG.

HOWEVER, if I attempt to drag an item past the bottom-most visible row of the ADG, the ADG does NOT scroll to display the next rows, which makes it impossible to drag and drop beyond the immediately visible rows. Although this would seem to be logical default behaviour of a datagrid (drag to bottom and keep dragging to reveal subsequent rows), Flex evidently doesn't Do Things That Way. I'm flummoxed how to implement this programatically.

Can anyone help?

도움이 되었습니까?

해결책

I had to do this with a few items in the past, basically what I did was monitor the mouses Y position in the DG, if it was 50 or fewer pixels from the top or bottom then I would set the verticalscrollposition of the DG += 20 or -= 20 as required.

Let me know if you need a code snip but you should be able to figure out how to do all of this.

다른 팁

this worked for me, from Andre's solution but also checking for maxVerticalScrollPosition and i was extending the ADG

    protected function onDragOver(event:DragEvent):void
    {
        var dropIndex:int = calculateDropIndex(event);

        autoScoll(dropIndex);
    }

    //to have the adg scroll when dragging
    //http://stackoverflow.com/questions/2913420/how-to-automate-vertical-scrolling-in-flex-advanceddatagrid-when-dragging-item-be
    protected function autoScoll(dropIndex:int):void
    {
        var rowsDisplayed:Number = rowCount;
        var topvisibleIndex:int = verticalScrollPosition;
        var botvisibleIndex:int = topvisibleIndex + rowsDisplayed;

        if (dropIndex <= topvisibleIndex)
        {
            verticalScrollPosition = Math.max(verticalScrollPosition - 1, 0);
        }
        else if (dropIndex >= botvisibleIndex - 1 && dropIndex < (rowCount + maxVerticalScrollPosition - 1))
        {
            verticalScrollPosition += 1;
        }
    }

Got to love Flex, man. Where the obvious stuff takes a ton of time.

So this is what I ended up doing:

mygrid.addEventListener( DragEvent.DRAG_OVER, handleDragOver);



public function handlerDragOver(event:DragEvent):void{
var dropIndex:int        = mygrid.calculateDropIndex(event);
var rowsDisplayed:Number = mygrid.rowCount;
var topvisibleIndex:int  = mygrid.verticalScrollPosition;
var botvisibleIndex:int  = topvisibleIndex + rowsDisplayed;


if ( dropIndex <= topvisibleIndex) {

    mygrid.verticalScrollPosition = Math.max( mygrid.verticalScrollPosition- 1, 0 );

} else if( dropIndex >= botvisibleIndex - 1 ){

mygrid.verticalScrollPosition += 1;
}

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top