Two controls, ListBox and Treeview, are used as the data source. You can drag the data to the Treeview to automatically add a tree node.
The ListBox control mousedown is used to obtain the value to be dragged and call the dodragdrop method.
Private Void Listbox1_mousedown ( Object Sender, mouseeventargs E)
{
// Call the dodragdrop Method
If ( This . Listbox1.selecteditem ! = Null )
{
This . Listbox1.dodragdrop ( This . Listbox1.selecteditem, dragdropeffects. copy );
}
}
The dragenter and dragdrop events of the Treeview control are used to receive data and add it as a tree node.
Private Void Treeviewincludragenter ( Object Sender, drageventargs E)
{
// Set the drag type (copy and drag here)
E. Effect = Dragdropeffects. copy;
}
Private Void Treeviewincludragdrop ( Object Sender, drageventargs E)
{
// Get value
String Item = ( String ) E. Data. getdata (E. Data. getformats ()[ 0 ]);
This. Treeview1.nodes. Add (item );
}
/Files/gossip/winformdraganddrop.rar source code download