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

Auto scroll Radtreeview when an item is dragged over

3 Answers 228 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Ranjitha
Top achievements
Rank 1
Ranjitha asked on 15 Dec 2020, 09:58 AM

I am trying to drag a text item from a Radgridview and drop onto a Node of RadTreeView. I have a custom code that is executed when it is dropped onto the node. My problem is, my treeView has around 200 nodes. I want the treeview to scroll down automatically, when the mouse is moved over ( to the visible last node), with the dragged item. How do I achieve this? Any help will be greatly appreciated.

 

Thanks,

Ranjitha

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Dec 2020, 01:13 PM

Hello, Ranjitha,   

According to the provided information, it is not clear enough what is the exact custom implementation that you have on your end. However, I believe that you are using the RadGridViewDragDropService that handles the whole drag and drop operation from RadGridView to any other RadControl: https://docs.telerik.com/devtools/winforms/controls/gridview/drag-and-drop/radgridviewdragdropservice 

RadTreeView supports auto-scroll on dragging behavior. But it is accomplished by the TreeViewDragDropService. The RadGridViewDragDropService which executes the drag/drop operation in this case is not expected to perform such an action. 
The possible solution that I can suggest is to scroll programmatically the RadTreeView control in the RadGridViewDragDropService.PreviewDragOver event:
        private void svc_PreviewDragOver(object sender, RadDragOverEventArgs e)
        {
            if (e.DragInstance is GridDataRowElement)
            { 
                e.CanDrop = e.HitTarget is RadTreeView ||
                            e.HitTarget is RadTreeViewElement ||
                            e.HitTarget is RadTreeNode ||
                            e.HitTarget is TreeNodeElement;

                TreeNodeElement targetNodeElement = e.HitTarget as TreeNodeElement;
                if (targetNodeElement!=null)
                {
                    MethodInfo mi = typeof(RadTreeViewElement).GetMethod("AutoScrollOnDragging", BindingFlags.Instance| BindingFlags.NonPublic);
                    mi.Invoke(targetNodeElement.TreeViewElement,new object[]{targetNodeElement}); 
                }
            }
        }

You can find attached a  complete sample project which result is illustrated in the provided gif file. Please have in mind that this is just a sample approach and it may not cover all possible cases. Feel free to modify and extend it in a way which suits your requirements best.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Ranjitha
Top achievements
Rank 1
answered on 16 Dec 2020, 01:14 AM
Thank you for your quick response Dess.

Below is my code:

  private void grid_MouseDown(object sender, MouseEventArgs e)
        {
            RadElement element = grid.ElementTree.GetElementAtPoint(e.Location);
            if (element is GridHeaderCellElement || element is ScrollBarThumb || element is GridFilterCellElement) return;
            if (e.Button == MouseButtons.Left && e.Clicks == 1)
            {
                List<string> coll = new List<string>();
                GridViewSelectedRowsCollection rows = grid.SelectedRows;
                foreach(var row in rows)
                {
                    coll.Add(row.Cells["Name"].Value.ToString());
                }
                treeview.DoDragDrop(coll, DragDropEffects.Copy);
            }
        }

        private void treeview_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
        }

        private void treeview_DragDrop(object sender, DragEventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            if (e.Data.GetDataPresent(typeof(List<string>)))
            {
                List<string> values = (List<string>)e.Data.GetData(typeof(List<string>));
                if (values == null || values.Count == 0) return;
                Point target = treeview.PointToClient(new Point(e.X, e.Y));
                RadTreeNode node = treeview.GetNodeAt(target);

               //Call my time taking API 
            }
            Cursor.Current = Cursors.Default;
        }

I am basically fetching cell values from multiple selected rows in the grid when drag operation is started, and when its dropped onto a tree node, an API is called to do some operation with the string list. No new nodes will be created in the treeview
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 Dec 2020, 07:51 AM

Hi, Ranjitha,

I can see that you use the OLE drag-and-drop functionality that all WinForms controls support. It is up to you how the custom drag-drop behavior will be accomplished on your end. I believe that the previously mentioned RadGridViewDragDropService can only improve handling the drag-drop operation on your end. 

However, the invoked AutoScrollOnDragging RadTreeView's method actually executes the scroll behavior in the tree view. Alternatively, you can manage the TreeViewElement.VScrollBar's value.

Feel free to use this approach which suits your scenario best. Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Treeview
Asked by
Ranjitha
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Ranjitha
Top achievements
Rank 1
Share this question
or