TreeView.SelectedNodeStyle Propiedad

Definición

Obtiene el objeto TreeNodeStyle que controla el aspecto del nodo seleccionado en el control TreeView.

public:
 property System::Web::UI::WebControls::TreeNodeStyle ^ SelectedNodeStyle { System::Web::UI::WebControls::TreeNodeStyle ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.TreeNodeStyle SelectedNodeStyle { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.SelectedNodeStyle : System.Web.UI.WebControls.TreeNodeStyle
Public ReadOnly Property SelectedNodeStyle As TreeNodeStyle

Valor de propiedad

TreeNodeStyle

Objeto TreeNodeStyle que representa el estilo del nodo seleccionado en el control TreeView. El valor predeterminado es null, que indica que no se ha establecido la propiedad SelectedNodeStyle.

Atributos

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar la SelectedNodeStyle propiedad para controlar la apariencia del nodo seleccionado en el TreeView control .


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    void Select_Change(Object sender, EventArgs e)
    {

        Message.Text = "You selected: " + LinksTreeView.SelectedNode.Text;

    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">
    <title>TreeView SelectedNodeStyle Example</title>
</head>
<body>
        <form id="form1" runat="server">
        
            <h3>TreeView SelectedNodeStyle Example</h3>

            <asp:TreeView id="LinksTreeView"
                Font-Names= "Arial"
                ForeColor="Blue"
                SelectedNodeStyle-ForeColor="Green"
                SelectedNodeStyle-VerticalPadding="0"
                OnSelectedNodeChanged="Select_Change"   
                runat="server">
                 
                <LevelStyles>
                
                    <asp:TreeNodeStyle ChildNodesPadding="10" 
                        Font-Bold="true" 
                        Font-Size="12pt" 
                        ForeColor="DarkGreen"/>
                    <asp:TreeNodeStyle ChildNodesPadding="5" 
                        Font-Bold="true" 
                        Font-Size="10pt"/>
                    <asp:TreeNodeStyle ChildNodesPadding="5" 
                        Font-UnderLine="true" 
                        Font-Size="10pt"/>
                    <asp:TreeNodeStyle ChildNodesPadding="10" 
                        Font-Size="8pt"/>
                         
                </LevelStyles>
                 
                <Nodes>
                
                    <asp:TreeNode Text="Table of Contents"
                        SelectAction="None">
                         
                        <asp:TreeNode Text="Chapter One">
                        
                            <asp:TreeNode Text="Section 1.0">
                            
                                <asp:TreeNode Text="Topic 1.0.1"/>
                                <asp:TreeNode Text="Topic 1.0.2"/>
                                <asp:TreeNode Text="Topic 1.0.3"/>
                            
                            </asp:TreeNode>
                            
                            <asp:TreeNode Text="Section 1.1">
                            
                                <asp:TreeNode Text="Topic 1.1.1"/>
                                <asp:TreeNode Text="Topic 1.1.2"/>
                                <asp:TreeNode Text="Topic 1.1.3"/>
                                <asp:TreeNode Text="Topic 1.1.4"/>
                            
                            </asp:TreeNode>
                        
                        </asp:TreeNode>
                        
                        <asp:TreeNode Text="Chapter Two">
                        
                            <asp:TreeNode Text="Section 2.0">
                            
                                <asp:TreeNode Text="Topic 2.0.1"/>
                                <asp:TreeNode Text="Topic 2.0.2"/>
                            
                            </asp:TreeNode>
                        
                        </asp:TreeNode>
                        
                    </asp:TreeNode>
                    <asp:TreeNode Text="Appendix A" />
                    <asp:TreeNode Text="Appendix B" />
                    <asp:TreeNode Text="Appendix C" />
                
                </Nodes>
                
            </asp:TreeView>
            
            <br /><br />
            
            <asp:Label id="Message" runat="server"/>
            
        </form>
    </body>
</html>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    Sub Select_Change(ByVal sender As Object, ByVal e As EventArgs)

        Message.Text = "You selected: " & LinksTreeView.SelectedNode.Text

    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">
    <title>TreeView SelectedNodeStyle Example</title>
</head>
<body>
        <form id="form1" runat="server">
        
            <h3>TreeView SelectedNodeStyle Example</h3>
            
            <asp:TreeView id="LinksTreeView"
                Font-Names= "Arial"
                ForeColor="Blue"
                SelectedNodeStyle-ForeColor="Green"
                SelectedNodeStyle-VerticalPadding="0"
                OnSelectedNodeChanged="Select_Change"   
                runat="server">
                 
                <LevelStyles>
                
                    <asp:TreeNodeStyle ChildNodesPadding="10" 
                        Font-Bold="true" 
                        Font-Size="12pt" 
                        ForeColor="DarkGreen"/>
                    <asp:TreeNodeStyle ChildNodesPadding="5" 
                        Font-Bold="true" 
                        Font-Size="10pt"/>
                    <asp:TreeNodeStyle ChildNodesPadding="5" 
                        Font-UnderLine="true" 
                        Font-Size="10pt"/>
                    <asp:TreeNodeStyle ChildNodesPadding="10" 
                        Font-Size="8pt"/>
                         
                </LevelStyles>
                 
                <Nodes>
                
                    <asp:TreeNode Text="Table of Contents"
                        SelectAction="None">
                         
                        <asp:TreeNode Text="Chapter One">
                        
                            <asp:TreeNode Text="Section 1.0">
                            
                                <asp:TreeNode Text="Topic 1.0.1"/>
                                <asp:TreeNode Text="Topic 1.0.2"/>
                                <asp:TreeNode Text="Topic 1.0.3"/>
                            
                            </asp:TreeNode>
                            
                            <asp:TreeNode Text="Section 1.1">
                            
                                <asp:TreeNode Text="Topic 1.1.1"/>
                                <asp:TreeNode Text="Topic 1.1.2"/>
                                <asp:TreeNode Text="Topic 1.1.3"/>
                                <asp:TreeNode Text="Topic 1.1.4"/>
                            
                            </asp:TreeNode>
                        
                        </asp:TreeNode>
                        
                        <asp:TreeNode Text="Chapter Two">
                        
                            <asp:TreeNode Text="Section 2.0">
                            
                                <asp:TreeNode Text="Topic 2.0.1"/>
                                <asp:TreeNode Text="Topic 2.0.2"/>
                            
                            </asp:TreeNode>
                        
                        </asp:TreeNode>
                        
                    </asp:TreeNode>
                    <asp:TreeNode Text="Appendix A" />
                    <asp:TreeNode Text="Appendix B" />
                    <asp:TreeNode Text="Appendix C" />
                
                </Nodes>
                
            </asp:TreeView>
            
            <br /><br />
            
            <asp:Label id="Message" runat="server"/>
            
        </form>
    </body>
</html>

Comentarios

Utilice la SelectedNodeStyle propiedad para controlar la apariencia del nodo seleccionado en el TreeView control . Esta propiedad es de solo lectura; sin embargo, puede establecer las propiedades del TreeNodeStyle objeto que devuelve. Las propiedades se pueden establecer declarativamente en el formulario Property-Subproperty, donde Subproperty es una propiedad del TreeNodeStyle objeto (por ejemplo, SelectedNodeStyle-ForeColor). Las propiedades también se pueden establecer mediante programación en el formulario Property.Subproperty (por ejemplo, SelectedNodeStyle.ForeColor). La configuración común suele incluir un color de fondo personalizado, el color de primer plano, las propiedades de fuente y el espaciado del nodo. Las propiedades de estilo se aplican en el siguiente orden de precedencia:

  1. NodeStyle.

  2. RootNodeStyle, ParentNodeStyleo LeafNodeStyle, según el tipo de nodo. Si se define la LevelStyles colección, se aplica en este momento, reemplazando las demás propiedades de estilo de nodo.

  3. SelectedNodeStyle.

  4. HoverNodeStyle.

Se aplica a

Consulte también