TreeViewEventArgs::Node Property

Gets the tree node that has been checked, expanded, collapsed, or selected.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

property TreeNode^ Node {
	TreeNode^ get ();

Property Value

Type: System.Windows.Forms::TreeNode
The TreeNode that has been checked, expanded, collapsed, or selected.

The following example illustrates a customized TreeView. By inheriting the TreeView class, this custom version has all the functionality of a normal TreeView. A unique appearance is provided by changing various property values in the constructor. Because ShowPlusMinus is set to false, the customized control also overrides OnAfterSelect so that nodes can be expanded and collapsed when they are clicked.

A control that is customized in this way can be used throughout an organization, making it easy to provide a consistent interface without requiring the control properties to be specified in each individual project.

public ref class CustomizedTreeView: public TreeView

      // Customize the TreeView control by setting various properties.
      BackColor = System::Drawing::Color::CadetBlue;
      FullRowSelect = true;
      HotTracking = true;
      Indent = 34;
      ShowPlusMinus = false;

      // The ShowLines property must be false for the FullRowSelect 
      // property to work.
      ShowLines = false;

   virtual void OnAfterSelect( TreeViewEventArgs^ e ) override
      // Confirm that the user initiated the selection. 
      // This prevents the first node from expanding when it is 
      // automatically selected during the initialization of 
      // the TreeView control. 
      if ( e->Action != TreeViewAction::Unknown )
         if ( e->Node->IsExpanded )

      // Remove the selection. This allows the same node to be 
      // clicked twice in succession to toggle the expansion state.
      SelectedNode = nullptr;

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft