This article excerpted the cool man in the blog garden. Http://www.cnblogs.com/jirigala
ExampleProgramHow is the running effect:
Note the following when dragging a node:
1: it is better to have prompt information when you drag it, so that you cannot find the information to be picked after misoperations.
2: I can't drag my father's day node to my child node. Isn't it an endless loop or a mess?
To enable the Treeview to support the drag and drop function, pay attention to the following attribute settings and corresponding events:Code.
The code implementation is as follows:
Private Void Tvorganize_itemdrag (
Object Sender, itemdrageventargs E)
{
If (
This . Permissionedit)
{
// Start the drag-and-drop operation, and set the drag-and-drop effect to move.
This . Dodragdrop (E. Item, dragdropeffects. Move );
}
}
Private VoidTvorganize_dragenter (ObjectSender, drageventargs E)
{
//Drag effect to move
E. effect = dragdropeffects. move;
}
Private Void Tvorganize_dragdrop (Object Sender, drageventargs E)
{
// Define an intermediate variable
Treenode;
// Determines whether the drag type is treenode. If not, it will not be processed.
If (E. Data. getdatapresent ( " System. Windows. Forms. treenode " , False ))
{
// Drag-and-drop target node
Treenode targettreenode;
// Obtains the coordinates of the current cursor.
// Defines the variable of a position and saves the coordinate point of the current cursor.
Point point = (Treeview) sender). pointtoclient ( New Point (E. X, E. y ));
// Obtain the node at the coordinate point based on the coordinate point
Targettreenode = (Treeview) sender). getnodeat (point );
// Get the dragged Node
Treenode = (treenode) E. Data. getdata (" System. Windows. Forms. treenode " );
// Determine whether the dragged node is the same as the target node.
If (Baseinterfacelogic. treenodecanmoveto (treenode, targettreenode ))
{
If (Basesysteminfo. showinformation)
{
// Move team?
If (MessageBox. Show (appmessage. Format (appmessage. msg0038, treenode. Text, targettreenode. Text), appmessage. msg0000, response. yesno, messageboxicon. Question) = dialogresult. No)
{
Return ;
}
}
Servicemanager. instance. organizeservice. moveTo (userinfo, treenode. Tag. tostring (), targettreenode. Tag. tostring ());
// Add a clone of the dragged node to the target node.
Targettreenode. nodes. Add (treenode) treenode. Clone ());
// Remove the dragged Node
Treenode. Remove ();
}
}
}