TreeView.HideSelection Property

Gets or sets a value indicating whether the selected tree node remains highlighted even when the tree view has lost the focus.

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

property bool HideSelection {
	bool get ();
	void set (bool value);
/** @property */
public boolean get_HideSelection ()

/** @property */
public void set_HideSelection (boolean value)

public function get HideSelection () : boolean

public function set HideSelection (value : boolean)

Property Value

true if the selected tree node is not highlighted when the tree view has lost the focus; otherwise, false. The default is true.

When this property is set to false, selected nodes in the TreeView control remain highlighted in a different color than the current selection color when the TreeView control loses focus. You can use this property to keep items that are selected by the user visible when the user clicks a different control on the form or moves to a different window.


If you are concerned with the accessibility of your applications, it is recommended that you set the HideSelection property to false.

The following code example demonstrates how to use the HideSelection property. To run this example, paste the following code in a form and call the InitializeSelectedTreeView method in the form's constructor or Load event handler.

No code example is currently available or this language may not be supported.
// Declare the TreeView control.
System.Windows.Forms.TreeView treeView2;

// Initialize the TreeView to blend with the form, giving it the 
// same color as the form and no border.
private void InitializeSelectedTreeView()
    // Create a new TreeView control and set the location and size.
    this.treeView2 = new System.Windows.Forms.TreeView();
    this.treeView2.set_Location(new System.Drawing.Point(72, 48));
    this.treeView2.set_Size(new System.Drawing.Size(200, 200));
    // Set the BorderStyle property to none, the BackColor property to
    // the form's backcolor, and the Scrollable property to false.  
    // This allows the TreeView to blend in form.
    // Set the HideSelection property to false to keep the 
    // selection highlighted when the user leaves the control. 
    // Add the nodes.
        new TreeNode[] {new TreeNode("Features",
        new TreeNode[] { new TreeNode("Full Color"),
        new TreeNode("Project Wizards"),
        new TreeNode("Visual C# and Visual Basic Support") }),
        new TreeNode("System Requirements",
        new TreeNode[] {
        new TreeNode("Pentium 133 MHz or faster processor "),
        new TreeNode("Windows 98 or later"),
        new TreeNode("100 MB Disk space") }) });
    // Set the tab index and add the TreeView to the form.

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