K
Kam
I've got a treeview and listview program which i would like to add a
drag and drop utility to it. i've managed to drag and drop items from
the treeview to the listview, from the treeview to itself. but i
cudn't do the same from the listview to the treeview.?!!
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();
}
}
}
//---------------------------------------------------
drag and drop utility to it. i've managed to drag and drop items from
the treeview to the listview, from the treeview to itself. but i
cudn't do the same from the listview to the treeview.?!!
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();
}
}
}
//---------------------------------------------------