- // The ItemDrag event is called when the item drag begins. Here is
- // where you can perform any tracking, or validate if the drag
- // operation should occur, and so on.
- private void myTree_ItemDrag(object sender, ItemDragEventArgs e)
- {
- sourceNode = (TreeNode) e.Item;
- DoDragDrop(e.Item.ToString(), DragDropEffects.Move | DragDropEffects.Copy);
- }
-
- // Define the event that occurs while the dragging happens
- private void myTree_DragEnter(object sender, DragEventArgs e)
- {
- if (e.Data.GetDataPresent(DataFormats.Text))
- {
- e.Effect = DragDropEffects.Move;
- else
- e.Effect = DragDropEffects.None;
- }
- }
-
- // Determine what node in the tree we are dropping on to (target),
- // copy the drag source (sourceNode), make the new node and delete
- // the old one.
- private void myTree_DragDrop(object sender, DragEventArgs e)
- {
- TreeNode targetNode = myTree.GetNodeAt(pos);
- TreeNode nodeCopy;
-
- if (targetNode != null)
- {
-
- if (sourceNode.Index > targetNode.Index)
- targetNode.Parent.Nodes.Insert(targetNode.Index, nodeCopy);
- else
- targetNode.Parent.Nodes.Insert(targetNode.Index + 1, nodeCopy);
-
- sourceNode.Remove();
- myTree.Invalidate();
- }
- }
track URL : clickhere
No comments:
Post a Comment