i would like to be able to drag and drop items/nodes from both to
either one of them and update the data automatically and refresh the
controls.
I don't know how to do this and i've got a very short time to do it.
Any help, examples or comments would be very much appreciated.
Thank you in advance.
Regards,
Kam
The treeview looks like:
Level1
--Level2
---Level3
and the code i've developed is as follows:
//-----------------------------------------------------
private void treeView1_ItemDrag(object sender,
System.Windows.Forms.ItemDragEventArgs e)
{
treeView1.DoDragDrop (e.Item, DragDropEffects.Move);
}
private void listView1_DragEnter(object sender,
System.Windows.Forms.DragEventArgs e)
{
if (e.Data.GetDataPresent (typeof (TreeNode)))
e.Effect = DragDropEffects.Move; //All or Copy (try)
}
private void listView1_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e)
{
if (e.Data.GetDataPresent (typeof (TreeNode)))
{
TreeNode tn = (TreeNode) e.Data.GetData
(typeof (TreeNode));
listView1.Items.Add (tn.Text, tn.ImageIndex);
treeView1.Nodes.Remove (tn);
}
}
private void listView1_ItemDrag(object sender,
System.Windows.Forms.ItemDragEventArgs e)
{
listView1.DoDragDrop (e.Item, DragDropEffects.Move);
}
private void treeView1_DragEnter(object sender,
System.Windows.Forms.DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void treeView1_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e)
{
TreeNode NewNode;
if(e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
{
Point pt = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
TreeNode DestinationNode = ((TreeView)sender).GetNodeAt(pt);
NewNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
if(DestinationNode!= NewNode)
{
DestinationNode.Nodes.Add((TreeNode) NewNode.Clone());
DestinationNode.Expand();
//Remove Original Node
NewNode.Remove();
}
}
}
//---------------------------------------------------
--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"Kam" <bas...@hotmail.com> wrote in message
news:53bfceca.03090...@posting.google.com...
i've managed to drag and drop as follows:
-treeview to itself
-treeview to listview
but i would like to be able to drag and drop from the listitem to the
treeview, update the database (which is not done in any of the above)
and refresh both controls with the new changes!
any idea? thank u and lookin forward for yr replies.
regards,
kam
By the way - do you see the mouse pointer change when you attempt dragging
an item from the ListView? Have you checked that the ItemDrag event fires?
Have you checked that the TreeView receives the DragDrop message and the
correct data object is obtained?
--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"Kam" <bas...@hotmail.com> wrote in message
news:53bfceca.03090...@posting.google.com...