This is a migrated thread and some comments may be shown as answers.

Auto scroll on drag and drop

6 Answers 118 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Luzius
Top achievements
Rank 1
Luzius asked on 31 Jan 2012, 08:25 AM
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

6 Answers, 1 is accepted

Sort by
0
Accepted
Nick
Telerik team
answered on 31 Jan 2012, 02:17 PM
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 >>

0
Luzius
Top achievements
Rank 1
answered on 31 Jan 2012, 02:29 PM
Hello Nik,

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

Thanks,
Luzius
0
Trang
Top achievements
Rank 1
answered on 11 Jul 2012, 06:18 PM
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
0
Licenses
Top achievements
Rank 1
answered on 29 Mar 2013, 10:02 AM
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
0
Nick
Telerik team
answered on 29 Mar 2013, 12:01 PM
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.

0
Licenses
Top achievements
Rank 1
answered on 29 Mar 2013, 02:43 PM
Hey Nik

I found the solution in the thread you gave.

Thanks
Sodi We
Tags
TreeListView
Asked by
Luzius
Top achievements
Rank 1
Answers by
Nick
Telerik team
Luzius
Top achievements
Rank 1
Trang
Top achievements
Rank 1
Licenses
Top achievements
Rank 1
Share this question
or