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)

Source: Internet
Author: User

        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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.