TreeNode.Clone Método

Definición

Copia el nodo de árbol y todo el subárbol con raíz en este nodo de árbol.Copies the tree node and the entire subtree rooted at this tree node.

public:
 virtual System::Object ^ Clone();
public virtual object Clone ();
abstract member Clone : unit -> obj
override this.Clone : unit -> obj
Public Overridable Function Clone () As Object

Devoluciones

Object que representa el TreeNode clonado.The Object that represents the cloned TreeNode.

Implementaciones

Ejemplos

En el ejemplo de código siguiente se clona el último nodo de árbol secundario del último nodo de árbol raíz y se inserta el clon como el primer nodo de TreeNodeCollectionárbol raíz en el.The following code example clones the last child tree node of the last root tree node and inserts the clone as the first root tree node in the TreeNodeCollection. Este ejemplo requiere que tenga TreeView un control Form en que contenga una colección de TreeNode objetos y un Button.This example requires that you have a TreeView control on a Form that contains a collection of TreeNode objects and a Button.

void button4_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   TreeNode^ lastNode = treeView1->Nodes[ treeView1->Nodes->Count - 1 ]->Nodes[ treeView1->Nodes[ treeView1->Nodes->Count - 1 ]->Nodes->Count - 1 ];
   
   // Clone the last child node.
   TreeNode^ clonedNode = dynamic_cast<TreeNode^>(lastNode->Clone());
   
   // Insert the cloned node as the first root node.
   treeView1->Nodes->Insert( 0, clonedNode );
   MessageBox::Show( String::Concat( lastNode->Text, " tree node cloned and added to ", treeView1->Nodes[ 0 ]->Text ) );
}

private void button4_Click(object sender, System.EventArgs e)
{
   TreeNode lastNode = treeView1.Nodes[treeView1.Nodes.Count - 1].
     Nodes[treeView1.Nodes[treeView1.Nodes.Count - 1].Nodes.Count - 1];

   // Clone the last child node.
   TreeNode clonedNode = (TreeNode) lastNode.Clone();

   // Insert the cloned node as the first root node.
   treeView1.Nodes.Insert(0, clonedNode);
   MessageBox.Show(lastNode.Text + 
     " tree node cloned and added to " + treeView1.Nodes[0].Text);
}
Private Sub button4_Click(sender As Object, _
  e As System.EventArgs) Handles button4.Click
   Dim lastNode as TreeNode
   lastNode = treeView1.Nodes(treeView1.Nodes.Count - 1). _
     Nodes(treeView1.Nodes(treeView1.Nodes.Count - 1).Nodes.Count - 1)

   ' Clone the last child node.
   Dim clonedNode As TreeNode = CType(lastNode.Clone(), TreeNode)

   ' Insert the cloned node as the first root node.
   treeView1.Nodes.Insert(0, clonedNode)
   MessageBox.Show(lastNode.Text & _
     " tree node cloned and added to " & treeView1.Nodes(0).Text)
End Sub

Comentarios

Se copia la estructura de árbol del nodo de árbol que se va a clonar.The tree structure from the tree node being cloned and below is copied. Los nodos de árbol secundarios asignados TreeNode al que se va a clonar se incluyen en el nuevo nodo de árbol y en el subárbol.Any child tree nodes assigned to the TreeNode being cloned are included in the new tree node and subtree.

El Clone método realiza una copia superficial del nodo.The Clone method performs a shallow copy of the node. Si el valor de la Tag propiedad es un tipo de referencia, tanto la copia original como la clonada apuntarán a la misma instancia única Tag del valor.If the value of the Tag property is a reference type, both the original and cloned copy will point to the same single instance of the Tag value.

Se aplica a

Consulte también: