I've got a problem, i got the nodes to move but
1. they copy nodes(if you drag it to 3 different places it will actually have 3 of the same nodes)
2. i want to make the nodes, if moved update the new nodes locations
This is my coding
1. they copy nodes(if you drag it to 3 different places it will actually have 3 of the same nodes)
2. i want to make the nodes, if moved update the new nodes locations
This is my coding
Code:
private void tvDescriptions_MouseDown(object sender, MouseEventArgs e)
{
TreeView tree = (TreeView)sender;
// Get the node underneath the mouse.
TreeNode node = tree.GetNodeAt(e.X, e.Y);
// Start the drag-and-drop operation with a cloned copy of the node.
if (node != null)
{
tree.DoDragDrop(node.Clone(), DragDropEffects.Copy);
}
}
private void tvDescriptions_DragOver(object sender, DragEventArgs e)
{
// Get the tree.
TreeView tree = (TreeView)sender;
// Drag and drop denied by default.
e.Effect = DragDropEffects.None;
// Is it a valid format?
if (e.Data.GetData(typeof(TreeNode)) != null)
{
// Get the screen point.
Point pt = new Point(e.X, e.Y);
// Convert to a point in the TreeView's coordinate system.
pt = tree.PointToClient(pt);
// Is the mouse over a valid node?
TreeNode node = tree.GetNodeAt(pt);
if (node != null)
{
e.Effect = DragDropEffects.Copy;
tree.SelectedNode = node;
}
}
}
private void tvDescriptions_DragDrop(object sender, DragEventArgs e)
{
// Get the tree.
TreeView tree = (TreeView)sender;
// Get the screen point.
Point pt = new Point(e.X, e.Y);
// Convert to a point in the TreeView's coordinate system.
pt = tree.PointToClient(pt);
// Get the node underneath the mouse.
TreeNode node = tree.GetNodeAt(pt);
// Add a child node.
node.Nodes.Add((TreeNode)e.Data.GetData(typeof(TreeNode)));
// Show the newly added node if it is not already visible.
node.Expand();
}
private void tvDescriptions_ItemDrag(object sender, ItemDragEventArgs e)
{
}
Comment