This documentation is archived and is not being maintained.

TreeViewHitTestInfo.Node Property

Gets the TreeNode at the position indicated by a hit test of a TreeView control.

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

public TreeNode Node { get; }

Property Value

Type: System.Windows.Forms.TreeNode
The TreeNode at the position indicated by a hit test of a TreeView control.

If the hit test location is not on a TreeNode, the Node property will be null.

The following code example demonstrates how to use the Node property. To run this example, create a Windows Form that contains a TreeView named treeView1, and populate it with several levels of nodes. Paste the following code into a form, and associate the MouseDown event of treeView1 with the treeView1_MouseDown method.


void treeView1_MouseDown(object sender, MouseEventArgs e)
{
    TreeViewHitTestInfo info = treeView1.HitTest(e.X, e.Y);
    TreeNode hitNode;
    if (info.Node != null) {
        hitNode = info.Node;
        MessageBox.Show(hitNode.Level.ToString());
    }
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: