This documentation is archived and is not being maintained.

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 System.Windows.Forms.dll)

public bool HideSelection { get; set; }

Property Value

Type: System.Boolean
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.

	// Declare the TreeView control.
	internal 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.Location = new System.Drawing.Point(72, 48);
		this.TreeView2.Size = new System.Drawing.Size(200, 200);

		this.TreeView2.BorderStyle = BorderStyle.Fixed3D;
		// Set the HideSelection property to false to keep the 
		// selection highlighted when the user leaves the control. 
		// This helps it blend with form.
		this.TreeView2.HideSelection = false;

		// Add the nodes.
		this.TreeView2.Nodes.AddRange(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.
		this.TreeView2.TabIndex = 0;

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.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.