Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-determine-which-treeview-node-was-clicked-windows-forms.md
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

2.3 KiB

title, ms.date, dev_langs, f1_keywords, helpviewer_keywords, ms.assetid
title ms.date dev_langs f1_keywords helpviewer_keywords ms.assetid
How to: Determine Which TreeView Node Was Clicked 03/30/2017
csharp
vb
cpp
TreeNode
examples [Windows Forms], TreeView control
tree nodes in TreeView control [Windows Forms], determining node clicked
TreeView control [Windows Forms], determining node clicked
06a4a191-d918-42af-9f49-956c93eff261

How to: Determine Which TreeView Node Was Clicked (Windows Forms)

When working with the Windows Forms xref:System.Windows.Forms.TreeView control, a common task is to determine which node was clicked, and respond appropriately.

To determine which TreeView node was clicked

  1. Use the xref:System.EventArgs object to return a reference to the clicked node object.

  2. Determine which node was clicked by checking the xref:System.Windows.Forms.TreeViewEventArgs class, which contains data related to the event.

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, _  
    ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect  
       ' Determine by checking the Node property of the TreeViewEventArgs.  
       MessageBox.Show(e.Node.Text)  
    End Sub  
    
    protected void treeView1_AfterSelect (object sender,
    System.Windows.Forms.TreeViewEventArgs e)  
    {  
       // Determine by checking the Text property.  
       MessageBox.Show(e.Node.Text);  
    }  
    
    private:  
       void treeView1_AfterSelect(System::Object ^  sender,  
          System::Windows::Forms::TreeViewEventArgs ^  e)  
       {  
          // Determine by checking the Text property.  
          MessageBox::Show(e->Node->Text);  
       }  
    

    Note

    As an alternative, you can use the xref:System.Windows.Forms.MouseEventArgs of the xref:System.Windows.Forms.Control.MouseDown or xref:System.Windows.Forms.Control.MouseUp event to get the xref:System.Drawing.Point.X%2A and xref:System.Drawing.Point.Y%2A coordinate values of the xref:System.Drawing.Point where the click occurred. Then, use the xref:System.Windows.Forms.TreeView control's xref:System.Windows.Forms.TreeView.GetNodeAt%2A method to determine which node was clicked.

See also