TreeViewHitTestInfo.Node Property

Definition

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

C#
public System.Windows.Forms.TreeNode Node { get; }
C#
public System.Windows.Forms.TreeNode? Node { get; }

Property Value

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

Examples

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.

C#
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());
    }
}

Remarks

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

Applies to

Product Versions
.NET Framework 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