TreeNodeStyleCollection 類別

定義

代表 TreeView 控制項中的 TreeNodeStyle 物件集合。

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 類別來指定控制項個別層級的 TreeView 樣式設定。 請注意,屬性 LevelStyles 會傳 TreeNodeStyleCollection 回 物件。


<%@ 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 。 類型的 LevelStylesTreeNodeStyleCollection 屬性會儲存樹狀結構個別層級的節點樣式。

屬性 LevelStyles 是個別樣式屬性的替代方案,例如 NodeStyle 屬性,可控制樹狀結構不同層級的節點樣式。 集合中的第一個樣式會對應至樹狀結構第一層中的節點樣式。 集合中的第二個樣式會對應至樹狀結構第二層中的節點樣式,依此類故。 不論 LevelStyles 節點是否具有子節點,屬性最常用來產生目錄樣式導覽功能表,其中特定層級的節點應該具有相同的外觀。

類別 TreeNodeStyleCollection 會繼承 StateManagedCollection 類別的大部分成員。 如需繼承成員的詳細資訊,請參閱 StateManagedCollection

屬性

Count

取得 StateManagedCollection 集合中所包含的項目數。

(繼承來源 StateManagedCollection)
Item[Int32]

取得或設定位於 TreeNodeStyle 物件中所指定索引處的 TreeNodeStyleCollection 物件。

方法

Add(TreeNodeStyle)

將指定的 TreeNodeStyle 物件附加至 TreeNodeStyleCollection 物件的結尾。

Clear()

將所有項目從 StateManagedCollection 集合中移除。

(繼承來源 StateManagedCollection)
Contains(TreeNodeStyle)

判斷指定的 TreeNodeStyle 物件是否在集合中。

CopyTo(Array, Int32)

從特定的陣列索引開始,將 StateManagedCollection 集合的項目複製到陣列。

(繼承來源 StateManagedCollection)
CopyTo(TreeNodeStyle[], Int32)

從目標陣列中的指定索引開始,從 TreeNodeStyleCollection 物件中,將所有項目複製至相容的一維陣列 TreeNodeStyle 物件。

CreateKnownType(Int32)

在衍生類別中覆寫時,建立實作 IStateManager 之類別的執行個體。 根據 GetKnownTypes() 方法所傳回之集合指定的成員,建立物件的類型。

(繼承來源 StateManagedCollection)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetEnumerator()

傳回逐一查看 StateManagedCollection 集合的列舉值。

(繼承來源 StateManagedCollection)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetKnownTypes()

在衍生類別中覆寫時,取得 StateManagedCollection 集合可以包含之 IStateManager 類型的陣列。

(繼承來源 StateManagedCollection)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IndexOf(TreeNodeStyle)

判斷集合中指定之 TreeNodeStyle 物件的索引。

Insert(Int32, TreeNodeStyle)

將指定的 TreeNodeStyle 物件插入 TreeNodeStyleCollection 物件的指定索引位置。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
OnClear()

在衍生類別中覆寫時,在 Clear() 方法移除集合的所有項目之前,執行額外工作。

(繼承來源 StateManagedCollection)
OnClearComplete()

在衍生類別中覆寫時,在 Clear() 方法完成移除集合的所有項目之後,執行額外工作。

(繼承來源 StateManagedCollection)
OnInsert(Int32, Object)

在衍生類別中覆寫時,在 IList.Insert(Int32, Object)IList.Add(Object) 方法將項目加入集合之前,執行額外工作。

(繼承來源 StateManagedCollection)
OnInsertComplete(Int32, Object)

在衍生類別中覆寫時,在 IList.Insert(Int32, Object)IList.Add(Object) 方法將項目加入集合之後,執行額外工作。

(繼承來源 StateManagedCollection)
OnRemove(Int32, Object)

在衍生類別中覆寫時,在 IList.Remove(Object)IList.RemoveAt(Int32) 方法從集合中移除指定的項目之前,執行額外工作。

(繼承來源 StateManagedCollection)
OnRemoveComplete(Int32, Object)

在衍生類別中覆寫時,在 IList.Remove(Object)IList.RemoveAt(Int32) 方法從集合中移除指定的項目之後,執行額外工作。

(繼承來源 StateManagedCollection)
OnValidate(Object)

在衍生類別中覆寫時,驗證 StateManagedCollection 集合的項目。

(繼承來源 StateManagedCollection)
Remove(TreeNodeStyle)

TreeNodeStyle 物件移除指定的 TreeNodeStyleCollection 物件。

RemoveAt(Int32)

TreeNodeStyle 物件的指定索引位置移除 TreeNodeStyleCollection 物件。

SetDirty()

強制整個 StateManagedCollection 集合序列化至檢視狀態。

(繼承來源 StateManagedCollection)
SetDirtyObject(Object)

在衍生類別中覆寫時,指示集合中所包含的 object,將其完整狀態 (而不只是變更資訊) 記錄至檢視狀態。

(繼承來源 StateManagedCollection)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

ICollection.Count

取得 StateManagedCollection 集合中所包含的項目數。

(繼承來源 StateManagedCollection)
ICollection.IsSynchronized

取得值,表示 StateManagedCollection 集合是否為同步 (安全執行緒)。 在所有情況下,這個方法都會傳回 false

(繼承來源 StateManagedCollection)
ICollection.SyncRoot

取得物件,可用來同步處理對 StateManagedCollection 集合的存取。 在所有情況下,這個方法都會傳回 null

(繼承來源 StateManagedCollection)
IEnumerable.GetEnumerator()

傳回逐一查看 StateManagedCollection 集合的列舉值。

(繼承來源 StateManagedCollection)
IList.Add(Object)

將項目加入 StateManagedCollection 集合。

(繼承來源 StateManagedCollection)
IList.Clear()

將所有項目從 StateManagedCollection 集合中移除。

(繼承來源 StateManagedCollection)
IList.Contains(Object)

判斷 StateManagedCollection 集合是否包含特定值。

(繼承來源 StateManagedCollection)
IList.IndexOf(Object)

判斷 StateManagedCollection 集合中指定之項目的索引。

(繼承來源 StateManagedCollection)
IList.Insert(Int32, Object)

將項目插入位於指定索引處的 StateManagedCollection 集合中。

(繼承來源 StateManagedCollection)
IList.IsFixedSize

取得值,表示 StateManagedCollection 集合是否具有固定大小。 在所有情況下,這個方法都會傳回 false

(繼承來源 StateManagedCollection)
IList.IsReadOnly

取得值,表示 StateManagedCollection 集合是否為唯讀。

(繼承來源 StateManagedCollection)
IList.Item[Int32]

取得指定索引處的 IStateManager 項目。

(繼承來源 StateManagedCollection)
IList.Remove(Object)

StateManagedCollection 集合中移除指定物件的第一個符合項目。

(繼承來源 StateManagedCollection)
IList.RemoveAt(Int32)

移除指定索引處的 IStateManager 項目。

(繼承來源 StateManagedCollection)
IStateManager.IsTrackingViewState

取得值,表示 StateManagedCollection 集合是否正在儲存變更至檢視狀態。

(繼承來源 StateManagedCollection)
IStateManager.LoadViewState(Object)

還原先前儲存之 StateManagedCollection 集合和內含 IStateManager 項目的檢視狀態。

(繼承來源 StateManagedCollection)
IStateManager.SaveViewState()

儲存自頁面回傳至伺服器以來 StateManagedCollection 集合和每個內含 IStateManager 物件的變更。

(繼承來源 StateManagedCollection)
IStateManager.TrackViewState()

使得 StateManagedCollection 集合和每個內含 IStateManager 物件追蹤其檢視狀態的變更,以便跨相同頁面要求保存這些變更。

(繼承來源 StateManagedCollection)

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。

AsParallel(IEnumerable)

啟用查詢的平行化作業。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

適用於

另請參閱