Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

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 */
public boolean get_HideSelection ()

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

public function get HideSelection () : boolean

public function set HideSelection (value : boolean)

Not applicable.

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.

NoteNote:

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;
    this.Controls.Add(this.TreeView2);
}

// 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.
    this.treeView2.set_BorderStyle(BorderStyle.Fixed3D);
           
    // Set the HideSelection property to false to keep the 
    // selection highlighted when the user leaves the control. 
    this.treeView2.set_HideSelection(false);
   
    // Add the nodes.
    this.treeView2.get_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.set_TabIndex(0);
    this.get_Controls().Add(this.treeView2);
} 

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.