TreeNode.EnsureVisible Method

Ensures that the tree node is visible, expanding tree nodes and scrolling the tree view control as necessary.

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

public void EnsureVisible ()
public void EnsureVisible ()
public function EnsureVisible ()

When the EnsureVisible method is called, the tree is expanded and scrolled to ensure that the current tree node is visible in the TreeView. This method is useful if you are selecting a tree node in code based on certain criteria. By calling this method after selecting the node, it ensures that the user can see and interact with the selected node.


If the TreeView.ItemHeight property is set to a value larger than the height of the tree view control, calling this method will have unexpected results.

The following code example brings the last child tree node of the last root tree node into view in the tree view when a button is clicked. This example requires that you have a TreeView control on a Form that contains a collection of TreeNode objects, and a Button. There should be enough tree nodes so they are not all visible in the tree view control.

private void button3_Click(object sender, System.EventArgs e)
   TreeNode lastNode = treeView1.Nodes[treeView1.Nodes.Count - 1].
     Nodes[treeView1.Nodes[treeView1.Nodes.Count - 1].Nodes.Count - 1];

   if (!lastNode.IsVisible)
      MessageBox.Show(lastNode.Text + " tree node is visible.");

private void button3_Click(Object sender, System.EventArgs e)
    TreeNode lastNode = treeView1.get_Nodes().get_Item(
        (treeView1.get_Nodes().get_Count() - 1)).get_Nodes().
        get_Count() - 1).get_Nodes().get_Count() - 1));

    if (!(lastNode.get_IsVisible())) {
        MessageBox.Show(lastNode.get_Text() + " tree node is visible.");
} //button3_Click

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions