Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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
public static TreeNode FromHandle(
 TreeView tree,
 IntPtr handle
public: static TreeNode* FromHandle(
 TreeView* tree,
 IntPtr handle
public static function FromHandle(
   tree : TreeView,
 handle : IntPtr
) : TreeNode;


The TreeView that contains the tree node.
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.


[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.
   ' Add tn to the TreeNodeCollection.
End Sub 

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.
   // Add tn to the TreeNodeCollection.

   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.
      // Add tn to the TreeNodeCollection.

[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.


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

© 2015 Microsoft