【问题标题】:Clone one node and its children by selecting/clicking in treeview通过在树视图中选择/单击来克隆一个节点及其子节点
【发布时间】:2016-02-05 08:48:10
【问题描述】:

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

【问题讨论】:

    标签: c# .net winforms treeview treenode


    【解决方案1】:
    //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
    

    【讨论】:

    • 我将命令写为:TreeNode select_node1 = new TreeNode(); select_node1 = treeView1.SelectedNode.Clone(); TreeNode copied_node1 = new TreeNode(); copied_node1.Nodes.Add(select_node1); bt 有错误。 Cannot implicitly convert type 'object' to 'System.Windows.Forms.TreeNode'.
    • 你想对选中/复制的 TreeNode 做什么?你想把它添加到 TreeView 吗?还是要将其添加到另一个 TreeNode?​​span>
    • 我想添加到另一个 TreeNode。
    • 代码更新:.clone返回一个对象,所以使用Ctype进行显式转换
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-19
    • 1970-01-01
    • 1970-01-01
    • 2014-08-12
    相关资源
    最近更新 更多