How to determine Which TreeView Node Was Clicked in TreeView Control in .net

This is very common task to determine which node was clicked, when we work with the windows Forms TreeView control. We use ‘AfterSelect’ event of the TreeView control. The ‘AfterSelect’ event has an event argument of the ‘TreeViewEventArgs’ class which contains the data related to selected Node and the Action (type of action that raised the event).

See the below implementation of the ‘AfterSelect’ event.
[vb]

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, _
          ByVal e As System.Windows.Forms.TreeViewEventArgs) _
                 Handles TreeView1.AfterSelect
   Dim node As TreeNode
   node = e.Node
   MessageBox.Show(node.Text)
End Sub

See the below c# code.
[c#]

protected void treeView1_AfterSelect (object sender, 
System.Windows.Forms.TreeViewEventArgs e)
{
   TreeNode node;
   node = e.Node;
   MessageBox.Show(node.Text);
}