Auto scroll on drag and drop

7 posts, 1 answers
  1. Luzius
    Luzius avatar
    14 posts
    Member since:
    Jun 2010

    Posted 31 Jan 2012 Link to this post

    Hi,

    There is a telerik 
    blog that shows how to implement autoscrolling when dragging items of a RadTreeView control using a behavior. I tried to adapt this to use with a RadTreeListView control but couldn't get it to work. Any idea of how to adapt it or of another approach?

    Thanks,
    Luzius
  2. Answer
    Nick
    Admin
    Nick avatar
    593 posts

    Posted 31 Jan 2012 Link to this post

    Hello Luzius,

    There are some minor differences between the TreeView and the TreeListView components. You have to make a few adjustments to the behavior presented in the blog post in order to use it with RadTreeListView.
    For starters, the type of the Behavior from which the AutoScrollBehavior derives should be RadTreeListView. Than instead of ScrollViewer, you should look for GridViewScrollViewer since this is the one that the GridViewDataControls use.

    In the end this is how it should look like: 

    public class TreeListAutoScrollBehavior : Behavior<RadTreeListView>
        {
            protected override void OnAttached()
            {
                base.OnAttached();
     
                EventManager.RegisterClassHandler(typeof(GridViewScrollViewer), RadDragAndDropManager.DropQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnTreeListViewScrollViewerDropQuery), true);
            }
     
            private static void OnTreeListViewScrollViewerDropQuery(object sender, DragDropQueryEventArgs e)
            {
                var scrollViewer = sender as GridViewScrollViewer;
     
                if (scrollViewer != null)
                {
     
                    var currentDragPoint = e.Options.CurrentDragPoint;
                    var generalTransform = scrollViewer.TransformToVisual(Application.Current.RootVisual);
                    var topLeft = generalTransform.Transform(new Point(0, 0));
                    var relative = new Point(currentDragPoint.X - topLeft.X, currentDragPoint.Y - topLeft.Y);
     
                    if (relative.Y > 0 && relative.Y < 40)
                    {
                        scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - (20 * ((40 - relative.Y) / 40)));
                    }
     
                    if (relative.Y > scrollViewer.ActualHeight - 40 && relative.Y < scrollViewer.ActualHeight)
                    {
                        scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + (20 * ((40 - (scrollViewer.ActualHeight - relative.Y)) / 40)));
                    }
     
                    if (relative.X > 0 && relative.X < 40)
                    {
                        scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset - (20 * ((40 - relative.X) / 40)));
                    }
     
                    if (relative.X > scrollViewer.ActualWidth - 40 && relative.X < scrollViewer.ActualWidth)
                    {
                        scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset + (20 * ((40 - (scrollViewer.ActualWidth - relative.X)) / 40)));
                    }
                }
            }
        }


    Hope this helps!  Regards,
    Nik
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Luzius
    Luzius avatar
    14 posts
    Member since:
    Jun 2010

    Posted 31 Jan 2012 Link to this post

    Hello Nik,

    It's working now. The GridViewScrollViewer instead of the ScrollViewer was the missing piece in my adaption.

    Thanks,
    Luzius
  5. Trang
    Trang avatar
    8 posts
    Member since:
    May 2012

    Posted 11 Jul 2012 Link to this post

    I'm using regular Listbox and implementing drag & drop on a child window.  I added the autoscrollbar behavior but the event is not firing.  Any idea?  I also use Scrollviewer?  Is this correct?  Please advice.

    Thanks
  6. Sodi We
    Sodi We avatar
    160 posts
    Member since:
    Apr 2010

    Posted 29 Mar 2013 Link to this post

    Hey,

    This code works perfect, but now we are migrating the raddraganddropmanager to the dragdropmanager.

    What event should we use instead of the RadDragAndDropManager.DropQueryEvent in the following code ? 

    EventManager.RegisterClassHandler(typeof(GridViewScrollViewer), RadDragAndDropManager.DropQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnTreeListViewScrollViewerDropQuery), true);


    Thanks Sodi We
  7. Nick
    Admin
    Nick avatar
    593 posts

    Posted 29 Mar 2013 Link to this post

    Hello Sodi,

    You can look into this thread to see how you can do the same with DragDropManager. 

    Hope it helps! 

    Kind regards,
    Nik
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Sodi We
    Sodi We avatar
    160 posts
    Member since:
    Apr 2010

    Posted 29 Mar 2013 Link to this post

    Hey Nik

    I found the solution in the thread you gave.

    Thanks
    Sodi We
Back to Top
DevCraft banner