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)

System::Object
  System::EventArgs
    System.Windows.Forms::TreeViewEventArgs

public ref class TreeViewEventArgs : EventArgs

NameDescription
System_CAPS_pubmethodTreeViewEventArgs(TreeNode^)

Initializes a new instance of the TreeViewEventArgs class for the specified tree node.

System_CAPS_pubmethodTreeViewEventArgs(TreeNode^, TreeViewAction)

Initializes a new instance of the TreeViewEventArgs class for the specified tree node and with the specified type of action that raised the event.

NameDescription
System_CAPS_pubpropertyAction

Gets the type of action that raised the event.

System_CAPS_pubpropertyNode

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

NameDescription
System_CAPS_pubmethodEquals(Object^)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

For more information about handling events, see Handling and Raising 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
{
public:
   CustomizedTreeView()
   {

      // 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;
   }

protected:
   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 )
         {
            e->Node->Collapse();
         }
         else
         {
            e->Node->Expand();
         }
      }


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

.NET Framework
Available since 1.1

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

Return to top
Show: