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.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft