Drag drop operation from telerik grid to windows form treeview(nor telrik treeview,simple windows control)

2 posts, 0 answers
  1. Sithara
    Sithara avatar
    1 posts
    Member since:
    Jul 2019

    Posted 02 Feb Link to this post

    Is it possible to drag a row from telerik grid to drop on windows form treeview control?

    In my code i am able to drag the row from telerik grid but DragEnter event of windows form treeview control is not firing?

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3988 posts

    Posted 03 Feb Link to this post

    Hello, Sithara,   

    In order to implement drag and drop behavior between a RadControl, e.g. RadGridView and a standard MS Control, e.g. TreeView, it is suitable to use the Ole drag-and-drop functionality. Please refer to the following help article demonstrating how to use it: https://docs.microsoft.com/en-us/dotnet/framework/winforms/advanced/walkthrough-performing-a-drag-and-drop-operation-in-windows-forms 

    I have prepared a very basic example to test whether the DragEnter event of the target TreeView will be fired and it seems to work as expected on my end:

            public RadForm1()
            {
                InitializeComponent();
    
                this.treeView1.AllowDrop = true;
                this.treeView1.DragEnter += treeView1_DragEnter;
    
                this.radGridView1.MouseDown += radGridView1_MouseDown;
                this.radGridView1.MouseMove += radGridView1_MouseMove;
            }
    
            private void radGridView1_MouseMove(object sender, MouseEventArgs e)
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Left && downLocation != Point.Empty)
                {
                    GridDataCellElement elementUnderMouse = this.radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridDataCellElement;
                    if (elementUnderMouse!=null)
                    {
                        this.radGridView1.DoDragDrop(elementUnderMouse.RowInfo, DragDropEffects.Move);
                    }
                }
            }
    
            Point downLocation = Point.Empty;
    
            private void radGridView1_MouseDown(object sender, MouseEventArgs e)
            {
                downLocation = e.Location;
            }
    
            private void treeView1_DragEnter(object sender, DragEventArgs e)
            {
                e.Effect = DragDropEffects.Move;
            }

    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

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top