在树视图中通过 selecting/clicking 克隆一个节点及其子节点

Clone one node and its children by selecting/clicking in treeview

如何通过单击或选择节点来克隆整个节点及其子节点?假设通过单击一个节点,它的子节点也被选中。然后就不需要检查它们是否已经被选中了。

//this example copies the selectednode from TreeViewTemplates to TreeForCopiedItem after you click a node.
//set the .afterselect-event of the treeview with the code below
//shouldn't be to hard to convert to C#
// Update : .clone returns an object, so use Ctype for explicit conversion

Private Sub TreeViewTemplates_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TreeViewTemplates.AfterSelect
    TreeForCopiedItem.Nodes.Clear()
    Dim copiedNode As TreeNode = CType(TreeViewTemplates.SelectedNode.Clone, TreeNode)
    TreeForCopiedItem.Nodes.Add(copiedNode)
End Sub