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

How to scroll during drag-and-drop

2 Answers 409 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Georg
Top achievements
Rank 1
Veteran
Georg asked on 10 Sep 2020, 06:49 PM

When the user drags an item to the top or bottom of the TreeListView, I'd like to scroll automatically, to handle the case where the user wants to drag to an item that isn't currently in view. I have a small sample program I can provide you, and OnDragOver is shown below. Can you tell me how to detect that the drag has reached the top or bottom of the view and then scroll as needed?

Thanks,

Georg Hentsch

        private void OnDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e) {
            var dropTarget = e.OriginalSource as TreeListViewRow ?? (e.OriginalSource as FrameworkElement).ParentOfType<TreeListViewRow>();
            var details = DragDropPayloadManager.GetDataFromObject(e.Data, "DropDetails") as DropIndicationDetails;

            if (dropTarget == null || details == null) {
                return;
            }

            details.CurrentDraggedOverItem = dropTarget.DataContext;

            if (details.CurrentDraggedItem == details.CurrentDraggedOverItem) {
                e.Effects = DragDropEffects.None;
                e.Handled = true;
                return;
            }

            details.CurrentDropPosition = GetDropPositionFromPoint(e.GetPosition(dropTarget), dropTarget);

            if (IsChildOf(dropTarget, sourceItem)) {
                e.Effects = DragDropEffects.None; // don't allow item to be dropped to one of its own children
            }

            e.Handled = true;
        }

 

2 Answers, 1 is accepted

Sort by
0
Georg
Top achievements
Rank 1
Veteran
answered on 12 Sep 2020, 02:45 PM
Actually, I think I see how to do this now, using "Point relativeLocation = row.TranslatePoint(new Point(0, 0), radTreeListView)" to determine where the row is in the view.
0
Georg
Top achievements
Rank 1
Veteran
answered on 12 Sep 2020, 03:27 PM

I got this working. In case anyone else needs this, here's the method I call from OnDragOver:

        private void ScrollIfNeeded(TreeListViewRow dropTarget) {
            Point dropPoint = dropTarget.TranslatePoint(new Point(0, 0), radTreeListView);
            int index = myObjects.IndexOf(dropTarget.Item);

            if (dropPoint.Y <= 3 * dropTarget.ActualHeight && index > 0) {
                // scroll previous row into view
                radTreeListView.ScrollIntoView(myObjects[index - 1]);
            } else if (dropPoint.Y >= radTreeListView.ActualHeight - 3 * dropTarget.ActualHeight && index < myObjects.Count - 1) {
                // scroll next row into view
                radTreeListView.ScrollIntoView(myObjects[index + 1]);
            }
        }



Tags
TreeListView
Asked by
Georg
Top achievements
Rank 1
Veteran
Answers by
Georg
Top achievements
Rank 1
Veteran
Share this question
or