TreeNodeStyleCollection 类

定义

表示 TreeView 控件中 TreeNodeStyle 对象的集合。Represents a collection of TreeNodeStyle objects that is in a TreeView control.

public ref class TreeNodeStyleCollection sealed : System::Web::UI::StateManagedCollection
public sealed class TreeNodeStyleCollection : System.Web.UI.StateManagedCollection
type TreeNodeStyleCollection = class
    inherit StateManagedCollection
Public NotInheritable Class TreeNodeStyleCollection
Inherits StateManagedCollection
继承
TreeNodeStyleCollection

示例

下面的代码示例演示如何使用 TreeNodeStyleCollection 类为控件的各个级别指定样式设置 TreeViewThe following code example demonstrates how to use the TreeNodeStyleCollection class to specify the style settings for the individual levels of a TreeView control. 请注意,该 LevelStyles 属性返回一个 TreeNodeStyleCollection 对象。Notice that the LevelStyles property returns a TreeNodeStyleCollection object.


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

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

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

      <!-- Populate the LevelStyles collection of the TreeView control -->
      <!-- declaratively.                                              -->
      
      <asp:TreeView id="LinksTreeView"
        Font-Names= "Arial"
        ForeColor="Blue"
        ShowExpandCollapse="false"
        ExpandDepth="3"
        NodeIndent="0" 
        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>

    </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">
<html xmlns="http://www.w3.org/1999/xhtml" >

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

      <!-- Populate the LevelStyles collection of the TreeView control -->
      <!-- declaratively.                                              -->
      
      <asp:TreeView id="LinksTreeView"
        Font-Names= "Arial"
        ForeColor="Blue"
        ShowExpandCollapse="false"
        ExpandDepth="3"
        NodeIndent="0" 
        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>

    </form>
  </body>
</html>

注解

TreeNodeStyleCollection类用于存储和管理 TreeNodeStyle 对象集合。The TreeNodeStyleCollection class is used to store and manage a collection of TreeNodeStyle objects. LevelStyles类型为的属性 TreeNodeStyleCollection 存储树的各个级别的节点样式。The LevelStyles property, of type TreeNodeStyleCollection, stores the node styles for the individual levels of a tree.

LevelStyles属性是单个样式属性(如属性)的替代方法,用于 NodeStyle 在树的不同级别控制节点样式。The LevelStyles property is an alternative to the individual style properties, such as the NodeStyle property, that control node styles at different levels of the tree. 集合中的第一种样式对应于树第一级的节点样式。The first style in the collection corresponds to the node style in the first level of the tree. 集合中的第二个样式对应于树第二级的节点样式,依此类推。The second style in the collection corresponds to the node style in the second level of the tree, and so on. LevelStyles属性最常用于生成目录样式的导航菜单,其中某个级别的节点应具有相同的外观,而不考虑它们是否具有子节点。The LevelStyles property is most often used to generate table of contents-style navigation menus where nodes at a certain level should have the same appearance, regardless of whether they have child nodes.

TreeNodeStyleCollection类从类继承其大部分成员 StateManagedCollectionThe TreeNodeStyleCollection class inherits most of its members from the StateManagedCollection class. 有关继承的成员的详细信息,请参阅 StateManagedCollectionFor more information about the inherited members, see StateManagedCollection.

属性

Count

获取 StateManagedCollection 集合中包含的元素的数量。Gets the number of elements contained in the StateManagedCollection collection.

(继承自 StateManagedCollection)
Item[Int32]

获取或设置 TreeNodeStyle 对象中指定索引处的 TreeNodeStyleCollection 对象。Gets or sets the TreeNodeStyle object at the specified index in the TreeNodeStyleCollection object.

方法

Add(TreeNodeStyle)

将指定的 TreeNodeStyle 对象追加到 TreeNodeStyleCollection 对象的结尾。Appends the specified TreeNodeStyle object to the end of the TreeNodeStyleCollection object.

Clear()

StateManagedCollection 集合中删除所有项。Removes all items from the StateManagedCollection collection.

(继承自 StateManagedCollection)
Contains(TreeNodeStyle)

确定指定的 TreeNodeStyle 对象是否在集合中。Determines whether the specified TreeNodeStyle object is in the collection.

CopyTo(Array, Int32)

从特定的数组索引开始,将 StateManagedCollection 集合的元素复制到数组中。Copies the elements of the StateManagedCollection collection to an array, starting at a particular array index.

(继承自 StateManagedCollection)
CopyTo(TreeNodeStyle[], Int32)

从目标数组的指定索引开始,将 TreeNodeStyleCollection 对象中的所有项复制到 TreeNodeStyle 对象的一维兼容数组。Copies all the items from the TreeNodeStyleCollection object to a compatible one-dimensional array of TreeNodeStyle objects, starting at the specified index in the target array.

CreateKnownType(Int32)

在派生类中替代时,创建实现 IStateManager 的类的实例。When overridden in a derived class, creates an instance of a class that implements IStateManager. 所创建对象的类型基于由 GetKnownTypes() 方法返回的集合的指定成员。The type of object created is based on the specified member of the collection returned by the GetKnownTypes() method.

(继承自 StateManagedCollection)
Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetEnumerator()

返回循环访问 StateManagedCollection 集合的迭代器。Returns an iterator that iterates through the StateManagedCollection collection.

(继承自 StateManagedCollection)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetKnownTypes()

在派生类中替代时,获取 StateManagedCollection 集合可以包含的 IStateManager 类型的数组。When overridden in a derived class, gets an array of IStateManager types that the StateManagedCollection collection can contain.

(继承自 StateManagedCollection)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IndexOf(TreeNodeStyle)

确定集合中指定 TreeNodeStyle 对象的索引。Determines the index of the specified TreeNodeStyle object in the collection.

Insert(Int32, TreeNodeStyle)

将指定的 TreeNodeStyle 对象插入 TreeNodeStyleCollection 对象中的指定索引位置。Inserts the specified TreeNodeStyle object into the TreeNodeStyleCollection object at the specified index location.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
OnClear()

在派生类中替代时,在 Clear() 方法从集合中删除所有项之前执行附加工作。When overridden in a derived class, performs additional work before the Clear() method removes all items from the collection.

(继承自 StateManagedCollection)
OnClearComplete()

在派生类中替代时,在 Clear() 方法完成从集合中删除所有项之后执行附加工作。When overridden in a derived class, performs additional work after the Clear() method finishes removing all items from the collection.

(继承自 StateManagedCollection)
OnInsert(Int32, Object)

在派生类中替代时,在 IList.Insert(Int32, Object)IList.Add(Object) 方法向集合中添加项之前执行附加工作。When overridden in a derived class, performs additional work before the IList.Insert(Int32, Object) or IList.Add(Object) method adds an item to the collection.

(继承自 StateManagedCollection)
OnInsertComplete(Int32, Object)

在派生类中替代时,在 IList.Insert(Int32, Object)IList.Add(Object) 方法向集合中添加项之后执行附加工作。When overridden in a derived class, performs additional work after the IList.Insert(Int32, Object) or IList.Add(Object) method adds an item to the collection.

(继承自 StateManagedCollection)
OnRemove(Int32, Object)

在派生类中替代时,在 IList.Remove(Object)IList.RemoveAt(Int32) 方法从集合中删除指定项之前执行附加工作。When overridden in a derived class, performs additional work before the IList.Remove(Object) or IList.RemoveAt(Int32) method removes the specified item from the collection.

(继承自 StateManagedCollection)
OnRemoveComplete(Int32, Object)

在派生类中替代时,在 IList.Remove(Object)IList.RemoveAt(Int32) 方法从集合中删除指定项之后执行附加工作。When overridden in a derived class, performs additional work after the IList.Remove(Object) or IList.RemoveAt(Int32) method removes the specified item from the collection.

(继承自 StateManagedCollection)
OnValidate(Object)

在派生类中替代时,验证 StateManagedCollection 集合的一个元素。When overridden in a derived class, validates an element of the StateManagedCollection collection.

(继承自 StateManagedCollection)
Remove(TreeNodeStyle)

TreeNodeStyle 对象中移除指定的 TreeNodeStyleCollection 对象。Removes the specified TreeNodeStyle object from the TreeNodeStyleCollection object.

RemoveAt(Int32)

TreeNodeStyle 对象中移除指定索引位置的 TreeNodeStyleCollection 对象。Removes the TreeNodeStyle object at the specified index location from the TreeNodeStyleCollection object.

SetDirty()

强制将整个 StateManagedCollection 集合序列化为视图状态。Forces the entire StateManagedCollection collection to be serialized into view state.

(继承自 StateManagedCollection)
SetDirtyObject(Object)

在派生类中替代时,指示集合包含的 object 将其全部状态记录到视图状态,而不是仅记录更改信息。When overridden in a derived class, instructs an object contained by the collection to record its entire state to view state, rather than recording only change information.

(继承自 StateManagedCollection)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

ICollection.Count

获取 StateManagedCollection 集合中包含的元素的数量。Gets the number of elements contained in the StateManagedCollection collection.

(继承自 StateManagedCollection)
ICollection.IsSynchronized

获取指示 StateManagedCollection 集合是否已同步(线程安全)的值。Gets a value indicating whether the StateManagedCollection collection is synchronized (thread safe). 此方法在所有情况下均返回 falseThis method returns false in all cases.

(继承自 StateManagedCollection)
ICollection.SyncRoot

获取可用于同步对 StateManagedCollection 集合的访问的对象。Gets an object that can be used to synchronize access to the StateManagedCollection collection. 此方法在所有情况下均返回 nullThis method returns null in all cases.

(继承自 StateManagedCollection)
IEnumerable.GetEnumerator()

返回循环访问 StateManagedCollection 集合的迭代器。Returns an iterator that iterates through the StateManagedCollection collection.

(继承自 StateManagedCollection)
IList.Add(Object)

StateManagedCollection 集合中添加一个项。Adds an item to the StateManagedCollection collection.

(继承自 StateManagedCollection)
IList.Clear()

StateManagedCollection 集合中删除所有项。Removes all items from the StateManagedCollection collection.

(继承自 StateManagedCollection)
IList.Contains(Object)

确定 StateManagedCollection 集合中是否包含特定值。Determines whether the StateManagedCollection collection contains a specific value.

(继承自 StateManagedCollection)
IList.IndexOf(Object)

确定 StateManagedCollection 集合中的指定项的索引。Determines the index of a specified item in the StateManagedCollection collection.

(继承自 StateManagedCollection)
IList.Insert(Int32, Object)

将项在指定索引处插入 StateManagedCollection 集合中。Inserts an item into the StateManagedCollection collection at the specified index.

(继承自 StateManagedCollection)
IList.IsFixedSize

获取指示 StateManagedCollection 集合是否具有固定大小的值。Gets a value indicating whether the StateManagedCollection collection has a fixed size. 此方法在所有情况下均返回 falseThis method returns false in all cases.

(继承自 StateManagedCollection)
IList.IsReadOnly

获取指示 StateManagedCollection 集合是否为只读的值。Gets a value indicating whether the StateManagedCollection collection is read-only.

(继承自 StateManagedCollection)
IList.Item[Int32]

获取指定索引处的 IStateManager 元素。Gets the IStateManager element at the specified index.

(继承自 StateManagedCollection)
IList.Remove(Object)

StateManagedCollection 集合中删除指定对象的第一个匹配项。Removes the first occurrence of the specified object from the StateManagedCollection collection.

(继承自 StateManagedCollection)
IList.RemoveAt(Int32)

删除指定索引处的 IStateManager 元素。Removes the IStateManager element at the specified index.

(继承自 StateManagedCollection)
IStateManager.IsTrackingViewState

获取指示 StateManagedCollection 集合是否保存对其视图状态的更改的值。Gets a value indicating whether the StateManagedCollection collection is saving changes to its view state.

(继承自 StateManagedCollection)
IStateManager.LoadViewState(Object)

还原 StateManagedCollection 集合以及其包含的 IStateManager 项的以前保存的视图状态。Restores the previously saved view state of the StateManagedCollection collection and the IStateManager items it contains.

(继承自 StateManagedCollection)
IStateManager.SaveViewState()

保存自页回发到服务器后对 StateManagedCollection 集合和该集合包含的每个 IStateManager 对象所做的更改。Saves the changes to the StateManagedCollection collection and each IStateManager object it contains since the time the page was posted back to the server.

(继承自 StateManagedCollection)
IStateManager.TrackViewState()

使 StateManagedCollection 集合及其包含的每个 IStateManager 对象跟踪对它们的视图状态所做的更改,以使它们可以在相同页的请求之间得以保持。Causes the StateManagedCollection collection and each of the IStateManager objects it contains to track changes to their view state so they can be persisted across requests for the same page.

(继承自 StateManagedCollection)

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于

另请参阅