--- title: "How to: Determine Which TreeView Node Was Clicked" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" - "cpp" f1_keywords: - "TreeNode" helpviewer_keywords: - "examples [Windows Forms], TreeView control" - "tree nodes in TreeView control [Windows Forms], determining node clicked" - "TreeView control [Windows Forms], determining node clicked" ms.assetid: 06a4a191-d918-42af-9f49-956c93eff261 --- # How to: Determine Which TreeView Node Was Clicked (Windows Forms) When working with the Windows Forms control, a common task is to determine which node was clicked, and respond appropriately. ### To determine which TreeView node was clicked 1. Use the object to return a reference to the clicked node object. 2. Determine which node was clicked by checking the class, which contains data related to the event. ```vb 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 ``` ```csharp protected void treeView1_AfterSelect (object sender, System.Windows.Forms.TreeViewEventArgs e) { // Determine by checking the Text property. MessageBox.Show(e.Node.Text); } ``` ```cpp 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 of the or event to get the and coordinate values of the where the click occurred. Then, use the control's method to determine which node was clicked. ## See also - [TreeView Control](treeview-control-windows-forms.md)