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:
The command "panel1.Controls.Add(test);" generates the exception.
What am I doing wrong?
Below is also the form designer code:
Thanks
Meir
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;
}
}
}
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