This documentation is archived and is not being maintained.

TreeNode.FromHandle Method

Returns the tree node with the specified handle and assigned to the specified tree view control.

[Visual Basic]
Public Shared Function FromHandle( _
   ByVal tree As TreeView, _
   ByVal handle As IntPtr _
) As TreeNode
[C#]
public static TreeNode FromHandle(
 TreeView tree,
 IntPtr handle
);
[C++]
public: static TreeNode* FromHandle(
 TreeView* tree,
 IntPtr handle
);
[JScript]
public static function FromHandle(
   tree : TreeView,
 handle : IntPtr
) : TreeNode;

Parameters

tree
The TreeView that contains the tree node.
handle
The handle of the tree node.

Return Value

A TreeNode that represents the tree node assigned to the specified TreeView control with the specified handle.

Example

[Visual Basic, C#, C++] The following example gets the TreeNode that was collapsed and creates a copy of it using its Handle property. The original TreeNode is removed from the TreeNodeCollection and the copy is added to the collection. This example assumes you have a Form with a TreeView control on it. The TreeView control should have two or more root nodes, each having at least one child node.

[Visual Basic] 
Private Sub treeView1_AfterCollapse(sender As Object, _
  e As TreeViewEventArgs) Handles treeView1.AfterCollapse
   ' Create a copy of the e.Node from its Handle.
   Dim tn As TreeNode = TreeNode.FromHandle(e.Node.TreeView, e.Node.Handle)
   tn.Text += "Copy"
   ' Remove the e.Node so it can be replaced with tn.
   e.Node.Remove()
   ' Add tn to the TreeNodeCollection.
   treeView1.Nodes.Add(tn)
End Sub 

[C#] 
private void treeView1_AfterCollapse(object sender, TreeViewEventArgs e)
{
   // Create a copy of the e.Node from its Handle.
   TreeNode tn = TreeNode.FromHandle(e.Node.TreeView, e.Node.Handle);
   tn.Text += "Copy";
   // Remove the e.Node so it can be replaced with tn.
   e.Node.Remove();
   // Add tn to the TreeNodeCollection.
   treeView1.Nodes.Add(tn);
}

[C++] 
private:
   void treeView1_AfterCollapse(Object* /*sender*/, TreeViewEventArgs* e) {
      // Create a copy of the e.Node from its Handle.
      TreeNode* tn = TreeNode::FromHandle(e->Node->TreeView, e->Node->Handle);
      tn->Text = String::Concat( tn->Text, S"Copy" );
      // Remove the e.Node so it can be replaced with tn.
      e->Node->Remove();
      // Add tn to the TreeNodeCollection.
      treeView1->Nodes->Add(tn);
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

TreeNode Class | TreeNode Members | System.Windows.Forms Namespace | TreeView | Handle

Show: