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

Error Drag RadTreeView Node to winform standard Panel

1 Answer 95 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
steive
Top achievements
Rank 1
steive asked on 05 Jan 2021, 01:06 PM

         i would like to drag RadTreeView Node to  winform standard Panel, but when i drag and drop  to the panel , my mouse always busying

         my code as fellows 

         

          panel   is   System.Windows.Forms.Panel panel

           this.tree  is  RadTreeView

 

           this.panel.AllowDrop = true;
            this.tree.AllowDrop = true;
           

            this.tree.ItemDrag  += Tree_ItemDrag;
            this.tree.DragEnter += new DragEventHandler(this.tree_FunctionList_DragEnter);

            this.panel.DragEnter += Panel_DragEnter;
            this.panel.DragDrop  += Panel_DragDrop;

 

        private void Tree_ItemDrag(object sender, RadTreeViewEventArgs e)
        {
            RadTreeNode tn = e.Node as RadTreeNode;
            if (tn != null)
            {
                (this.tree).DoDragDrop(tn, DragDropEffects.Copy);
            }
        }

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



        private void Panel_DragDrop(object sender, DragEventArgs e)
        {
            RadTreeNode node = e.Data.GetData(typeof(RadTreeNode)) as RadTreeNode;
            Console.WriteLine(node.Text);
        }

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

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 Jan 2021, 06:22 AM
Hello, Steive,   

Following the provided information, I have prepared a sample code snippet for your reference:
        public RadForm1()
        {
            InitializeComponent();

            this.panel1.AllowDrop = true; 
           
            this.radTreeView1.MouseDown += radTreeView1_MouseDown;  

            this.panel1.DragEnter += Panel_DragEnter;
            this.panel1.DragDrop += Panel_DragDrop;
        }

        private void radTreeView1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left && this.radTreeView1.SelectedNode != null)
            {
                (this.radTreeView1).DoDragDrop(this.radTreeView1.SelectedNode, DragDropEffects.Copy);
            }
        }

        private void Panel_DragDrop(object sender, DragEventArgs e)
        {
            RadTreeNode node = e.Data.GetData(typeof(RadTreeNode)) as RadTreeNode;
            Console.WriteLine(node.Text);
        }

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

The achieved result is illustrated in the attached gif file. It seems that everything works as expected on my end. Am I missing something?

I have attached my sample project. Please give it a try and see how it works on your end. 

The following MSDN article is quite useful about implementing drag and drop functionality: https://docs.microsoft.com/en-us/dotnet/desktop/winforms/advanced/walkthrough-performing-a-drag-and-drop-operation-in-windows-forms?view=netframeworkdesktop-4.8  

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/.

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