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

Exception with Drag and Drop

3 Answers 326 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Adiel
Top achievements
Rank 1
Adiel asked on 14 Jan 2013, 04:15 PM
I have a problem when dragging a tree node into a panel. In the  Drag Drop event of the panel , I try to add a control to the panel and then I get the following exception :

System.ComponentModel.Win32Exception was unhandled by user code
  Message=Error creating window handle.
  Source=System.Windows.Forms
  ErrorCode=-2147467259
  NativeErrorCode=1411
  StackTrace:
       at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
       at System.Windows.Forms.Control.CreateHandle()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.ControlCollection.Add(Control value)
       at TestTreeView.Form1.panel1_DragDrop(Object sender, DragEventArgs e) in E:\Users\Meir\Documents\Visual Studio 2010\Projects\MilestoneTesting\TestTreeView\Form1.cs:line 37
       at System.Windows.Forms.Control.OnDragDrop(DragEventArgs drgevent)
       at System.Windows.Forms.Control.System.Windows.Forms.IDropTarget.OnDragDrop(DragEventArgs drgEvent)
       at System.Windows.Forms.DropTarget.System.Windows.Forms.UnsafeNativeMethods.IOleDropTarget.OleDrop(Object pDataObj, Int32 grfKeyState, Int64 pt, Int32& pdwEffect)
  InnerException: 


This does not happen to me if I am using Microsoft Tree control. 
I am using Telerik for Windows Forms , updated to Dec 11, 2012

Here is the code snippet:
using System;
using System.Linq;
 
using System.Windows.Forms;
using Telerik.WinControls.UI;
 
namespace TestTreeView
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
             
            radTreeView1.AddNodeByPath("\\test");
            radTreeView1.ExpandAll();
            radTreeView1.ShowFeedbackForm = false;
        }
 
        private void radTreeView1_DragStarted(object sender, Telerik.WinControls.UI.RadTreeViewDragEventArgs e)
        {
            DoDragDrop(e.Node, DragDropEffects.Move);
        }
 
        private void panel1_DragDrop(object sender, DragEventArgs e)
        {
            Label test = new Label();
            panel1.Controls.Add(test);
        }
 
        private void panel1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Move;
        }
 
   
 
    }
}

The command "panel1.Controls.Add(test);" generates the exception.
What am I doing wrong?

Below is also the  form designer code:
namespace TestTreeView
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
 
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
        #region Windows Form Designer generated code
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.radTreeView1 = new Telerik.WinControls.UI.RadTreeView();
            this.panel1 = new System.Windows.Forms.Panel();
            ((System.ComponentModel.ISupportInitialize)(this.radTreeView1)).BeginInit();
            this.SuspendLayout();
            //
            // radTreeView1
            //
            this.radTreeView1.AllowDragDrop = true;
            this.radTreeView1.AllowDrop = true;
            this.radTreeView1.Location = new System.Drawing.Point(31, 35);
            this.radTreeView1.Name = "radTreeView1";
            this.radTreeView1.Size = new System.Drawing.Size(243, 348);
            this.radTreeView1.SpacingBetweenNodes = -1;
            this.radTreeView1.TabIndex = 0;
            this.radTreeView1.Text = "radTreeView1";
            this.radTreeView1.DragStarted += new Telerik.WinControls.UI.RadTreeView.DragStartedHandler(this.radTreeView1_DragStarted);
            //
            // panel1
            //
            this.panel1.AllowDrop = true;
            this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.panel1.Location = new System.Drawing.Point(289, 127);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(146, 100);
            this.panel1.TabIndex = 1;
            this.panel1.DragDrop += new System.Windows.Forms.DragEventHandler(this.panel1_DragDrop);
            this.panel1.DragEnter += new System.Windows.Forms.DragEventHandler(this.panel1_DragEnter);
             
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(475, 395);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.radTreeView1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.radTreeView1)).EndInit();
            this.ResumeLayout(false);
 
        }
 
        #endregion
 
        private Telerik.WinControls.UI.RadTreeView radTreeView1;
        private System.Windows.Forms.Panel panel1;
    }
}


Thanks
Meir

3 Answers, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 16 Jan 2013, 01:22 PM
Hi Meir,

I did not manage to reproduce the issue. I suppose that it happens due to mixing the Microsoft OLE Drag and Drop with Telerik Drag and Drop approach. I recommend using the Telerik Drag and Drop approach in cooperation with
RadPanel instead of Microsoft Panel.

You should use the following code snippets as sample:
public partial class TestTreeView : Form
    {
        public TestTreeView()
        {
            InitializeComponent();
 
            this.panel1.PanelElement.AllowDrop = true;
            this.radTreeView1.TreeViewElement.DragDropService.PreviewDragDrop += this.OnPreviewDragDrop;
            this.radTreeView1.TreeViewElement.DragDropService.PreviewDragOver += this.OnPreviewDragOver;
        }
 
        void OnPreviewDragOver(object sender, Telerik.WinControls.RadDragOverEventArgs e)
        {
            RadPanelElement panelElement = e.HitTarget as RadPanelElement;
 
            if (panelElement != null)
            {
                e.CanDrop = true;
            }
        }
 
        void OnPreviewDragDrop(object sender, Telerik.WinControls.RadDropEventArgs e)
        {
            RadPanelElement panelElement = e.HitTarget as RadPanelElement;
 
            if (panelElement != null)
            {
                Label test = new Label();
                test.Text = "Hello";
                panel1.Controls.Add(test);
                e.Handled = true;
            }
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
            radTreeView1.AddNodeByPath("\\test");
            radTreeView1.ExpandAll();
            //   radTreeView1.ShowFeedbackForm = false;
        }
    }

partial class TestTreeView
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
 
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
        #region Windows Form Designer generated code
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.radTreeView1 = new Telerik.WinControls.UI.RadTreeView();
            this.panel1 = new Telerik.WinControls.UI.RadPanel();
            ((System.ComponentModel.ISupportInitialize)(this.radTreeView1)).BeginInit();
            this.SuspendLayout();
            //
            // radTreeView1
            //
            this.radTreeView1.AllowDragDrop = true;
            this.radTreeView1.AllowDrop = true;
            this.radTreeView1.Location = new System.Drawing.Point(31, 35);
            this.radTreeView1.Name = "radTreeView1";
            this.radTreeView1.Size = new System.Drawing.Size(243, 348);
            this.radTreeView1.SpacingBetweenNodes = -1;
            this.radTreeView1.TabIndex = 0;
            this.radTreeView1.Text = "radTreeView1";
            //
            // panel1
            //
            this.panel1.AllowDrop = true;
            this.panel1.Location = new System.Drawing.Point(289, 127);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(146, 100);
            this.panel1.TabIndex = 1;
 
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(475, 395);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.radTreeView1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.radTreeView1)).EndInit();
            this.ResumeLayout(false);
 
        }
 
        #endregion
 
        private Telerik.WinControls.UI.RadTreeView radTreeView1;
        private Telerik.WinControls.UI.RadPanel panel1;
    }
All the best,
Svett
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
Adiel
Top achievements
Rank 1
answered on 17 Jan 2013, 12:41 PM
Hi Svett,

Thank you for your reply. The solution you provide answers the issue when the panel control is just an empty Telerik panel, but does not solve the problem I am facing. I am trying to Drag & Drop nodes from a tree to a panel that is sometimes is  empty and in other times has a ActiveX. Since the Drag and Drop services of Telerik, only work with Telerik controls, when the panel contains a non-Telerik control such as an ActiveX , this method does not work.
I was hoping that the RadTreeView will work with the simple Windows drag and drop services instead of the Telerik Drag & drop services , since I am using the Windows D&D services  with the RadGridview control to drag rows to the panel ,  where it does work.  I was expecting the RadTreeView to work just like the RadGridView.


Thanks 
Meir
0
Svett
Telerik team
answered on 21 Jan 2013, 10:05 AM
Hello Meir,

You should not mix the Telerik drag and drop and Microsoft OLE Drag and Drop. In your scenario you should use the Microsoft OLE Drag and Drop. You can read more about how you can do that in
MSDN.

Kind regards,
Svett
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Tags
Treeview
Asked by
Adiel
Top achievements
Rank 1
Answers by
Svett
Telerik team
Adiel
Top achievements
Rank 1
Share this question
or