TreeView.AfterSelect Event

Definition

Occurs after the tree node is selected.

public event System.Windows.Forms.TreeViewEventHandler AfterSelect;
public event System.Windows.Forms.TreeViewEventHandler? AfterSelect;

Event Type

Examples

The following code example demonstrates how to use the TreeViewAction enumeration. To run this example, paste the following code in a form that contains a TreeView control named TreeView1. This example requires that TreeView1 is populated with items and the AfterSelect event is connected to the event handler defined in the sample.

// Handle the After_Select event.
private void TreeView1_AfterSelect(System.Object sender, 
    System.Windows.Forms.TreeViewEventArgs e)
{

    // Vary the response depending on which TreeViewAction
    // triggered the event. 
    switch((e.Action))
    {
        case TreeViewAction.ByKeyboard:
            MessageBox.Show("You like the keyboard!");
            break;
        case TreeViewAction.ByMouse:
            MessageBox.Show("You like the mouse!");
            break;
    }
}

Remarks

This event does not occur when the node is unselected. To detect whether the selection was cleared, you can test the TreeNode.IsSelected property.

For more information about handling events, see Handling and Raising Events.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also