--- title: "How to: Attach a ShortCut Menu to a TreeView Node" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" - "cpp" helpviewer_keywords: - "shortcut menus [Windows Forms], adding to TreeView controls" - "TreeView control [Windows Forms], adding shortcut menus" - "tree nodes in TreeView control [Windows Forms], shortcut menus" ms.assetid: a23c6752-fd8f-44ad-b781-bab37962fc7c --- # How to: Attach a ShortCut Menu to a TreeView Node The Windows Forms control displays a hierarchy of nodes, similar to the files and folders displayed in the left pane of Windows Explorer. By setting the property, you can provide context-sensitive operations to the user when they right-click the control. By associating a component with individual items, you can add a customized level of shortcut menu functionality to your controls. ### To associate a shortcut menu with a TreeNode programmatically 1. Instantiate a control with the appropriate property settings, create a root , and then add subnodes. 2. Instantiate a component, and then add a for each operation you want to make available at run time. 3. Set the property of the appropriate to the shortcut menu you create. 4. When this property is set, the shortcut menu will be displayed when you right-click the node. The following code example creates a basic and associated with the root of the . You will need to customize the menu choices to those that fit the you are developing. Additionally, you will want to write code to handle the events for these menu items. [!code-cpp[System.Windows.Forms.TreeNodeContextMenuStrip#1](~/samples/snippets/cpp/VS_Snippets_Winforms/system.windows.forms.TreeNodeContextMenuStrip/cpp/Form1.cpp#1)] [!code-csharp[System.Windows.Forms.TreeNodeContextMenuStrip#1](~/samples/snippets/csharp/VS_Snippets_Winforms/system.windows.forms.TreeNodeContextMenuStrip/CS/Form1.cs#1)] [!code-vb[System.Windows.Forms.TreeNodeContextMenuStrip#1](~/samples/snippets/visualbasic/VS_Snippets_Winforms/system.windows.forms.TreeNodeContextMenuStrip/VB/Form1.vb#1)] ## See also - - [TreeView Control](treeview-control-windows-forms.md)