* 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
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 |
|
|
|
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
-
Use the xref:System.EventArgs object to return a reference to the clicked node object.
-
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 Subprotected 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.