TreeNodeTypes 列舉

定義

表示 TreeView 控制項中不同的節點型別,包括分葉、父代 (Parent) 和根 (Root)。

此列舉支援其成員值的位元組合。

public enum class TreeNodeTypes
[System.Flags]
public enum TreeNodeTypes
[<System.Flags>]
type TreeNodeTypes = 
Public Enum TreeNodeTypes
繼承
TreeNodeTypes
屬性

欄位

All 7

所有節點。

Leaf 4

沒有子節點的節點。

None 0

沒有節點。

Parent 2

有一個父節點和一或多個子節點的節點。

Root 1

沒有父節點、但有一或多個子節點的節點。

範例

下列範例示範如何使用 TreeNodeTypes 列舉來指出 TreeView 控制項應該只顯示每個父節點和分葉節點的核取方塊:


<%@ 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 Button_Click(Object sender, EventArgs e)
  {

    if(LinksTreeView.CheckedNodes.Count > 0)
    {

      // Clear the message label.
      Message.Text = "You selected: <br /><br />";

      // Iterate through the CheckedNodes collection and display the selected nodes.
      foreach (TreeNode node in LinksTreeView.CheckedNodes)
      {

        Message.Text += node.Text + "<br />";

      }

    }

    else
    {

      Message.Text = "No items selected.";

    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView ShowCheckBoxes Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView ShowCheckBoxes Example</h3>
    
      <!-- Set the ShowCheckBoxes property declaratively.   -->
      <!-- Because the ShowCheckBoxes property uses a flag  -->
      <!-- enumeration, you can combine multiple values by  -->
      <!-- using the bitwise OR operator. In declarative    -->
      <!-- syntax, this is done using a comma separated     -->
      <!-- list.                                            -->
      <asp:TreeView id="LinksTreeView"
        Font-Names= "Arial"
        ForeColor="Blue"
        ExpandDepth="2"
        ShowCheckBoxes="Parent,Leaf" 
        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:Button id="Submit"
        Text="Select Items"
        OnClick="Button_Click"  
        runat="server"/>
         
      <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 Button_Click(ByVal sender As Object, ByVal e As EventArgs)

    If LinksTreeView.CheckedNodes.Count > 0 Then

      ' Clear the message label.
      Message.Text = "You selected: <br /><br />"

      ' Iterate through the CheckedNodes collection and display the selected nodes.
      Dim node As TreeNode
      
      For Each node In LinksTreeView.CheckedNodes

        Message.Text &= node.Text & "<br />"

      Next

    Else

      Message.Text = "No items selected."

    End If

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView ShowCheckBoxes Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView ShowCheckBoxes Example</h3>
    
      <!-- Set the ShowCheckBoxes property declaratively.   -->
      <!-- Because the ShowCheckBoxes property uses a flag  -->
      <!-- enumeration, you can combine multiple values by  -->
      <!-- using the bitwise OR operator. In declarative    -->
      <!-- syntax, this is done using a comma separated     -->
      <!-- list.                                            -->
      <asp:TreeView id="LinksTreeView"
        Font-Names= "Arial"
        ForeColor="Blue"
        ExpandDepth="2"
        ShowCheckBoxes="Parent,Leaf" 
        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:Button id="Submit"
        Text="Select Items"
        OnClick="Button_Click"  
        runat="server"/>
         
      <br /><br />
      
      <asp:Label id="Message"
        runat="server"/>

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

備註

列舉 TreeNodeTypes 是用來表示 控制項中 TreeView 可用的不同節點類型。 下表描述三種不同的節點類型:

節點類型 描述
Leaf 沒有子節點的節點。
Parent 有一個父節點和一或多個子節點的節點。
Root 沒有父節點、但有一或多個子節點的節點。

列舉 TreeNodeTypes 是旗標列舉,可讓您透過位運算合併值。 例如,若要表示父節點和分葉節點,您可以在 和 Leaf 值上 Parent 執行位 OR 運算。

注意

屬性 TreeView.ShowCheckBoxesTreeNodeTypes 使用 列舉來表示控制項中顯示覆選框的 TreeView 節點類型。 當它設定為 以外的 None 值時,核取方塊會顯示在指定的節點類型旁邊,讓使用者從 TreeView 控制項中選取多個專案。

適用於

另請參閱