This documentation is archived and is not being maintained.

TreeViewEventArgs Class

Provides data for the AfterCheck, AfterCollapse, AfterExpand, or AfterSelect events of a TreeView control.

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

public ref class TreeViewEventArgs : public EventArgs

For more information about handling events, see Consuming Events.

The following example illustrates a customized TreeView. By inheriting the TreeView class, this custom version has all the functionality of a normal TreeView. Changing various property values in the constructor provides a unique appearance. Because the ShowPlusMinus property is set to false, the customized control also overrides the OnAfterSelect method so 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;


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0