Private intDraptype=1;//1: Non-sibling, not 1: Drag sibling Private voidTreeview1_itemdrag (Objectsender, ItemDragEventArgs e) { if(E.button = =mousebuttons.left) {DoDragDrop (E.item, DragDropEffects.Move); } } Private voidTreeview1_dragenter (Objectsender, DragEventArgs e) { if(E.data.getdatapresent (typeof(TreeNode))) E.effect=DragDropEffects.Move; ElseE.effect=DragDropEffects.None; } Private voidTreeview1_dragdrop (Objectsender, DragEventArgs e) { //get a node in a drag and dropTreeNode MoveNode = (TreeNode) e.data.getdata ("System.Windows.Forms.TreeNode"); //determines the target node to move to, based on mouse coordinatesPoint pt = ((TreeView) sender). PointToClient (NewPoint (e.x, e.y)); TreeNode TargetNode=Treeview1.getnodeat (PT); //If the target node is a group, it is added to the end of the subordinate node, and if the target node is a footage file, it is added as a sibling nodeTreeNode Newmovenode =(TreeNode) Movenode.clone (); if(Draptype = =1) {TargetNode.Nodes.Insert (TargetNode.Nodes.Count, Newmovenode); } Else { if(Movenode.nextnode = =TargetNode) {TargetNode.Parent.Nodes.Insert (Targetnode.index+1, Newmovenode); } Else{TargetNode.Parent.Nodes.Insert (Targetnode.index, Newmovenode); } } //updates the currently dragged node selectionTreeview1.selectednode =Newmovenode; //Expand the target node for easy display of drag and drop effectsTargetnode.expand (); //Removing a dragged nodeMovenode.remove (); }
The TreeView control in WinForm implements the mouse-dragged node (which can be interchanged at the sibling node or dragged to the target child node)