TreeView.CheckedNodes プロパティ

定義

選択したチェック ボックスを表示する TreeNode コントロール内のノードを表す TreeView オブジェクトのコレクションを取得します。

public:
 property System::Web::UI::WebControls::TreeNodeCollection ^ CheckedNodes { System::Web::UI::WebControls::TreeNodeCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.UI.WebControls.TreeNodeCollection CheckedNodes { get; }
[<System.ComponentModel.Browsable(false)>]
member this.CheckedNodes : System.Web.UI.WebControls.TreeNodeCollection
Public ReadOnly Property CheckedNodes As TreeNodeCollection

プロパティ値

選択したチェック ボックスを表示する TreeNodeCollection 内のノードを格納する TreeView

属性

次のコード例では、 プロパティをCheckedNodes使用して、コントロール内で選択されたチェック ボックスを持つノードを確認する方法を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>

注釈

チェック ボックスがコントロールにTreeView表示される場合 (プロパティを 以外TreeNodeType.NoneShowCheckBoxes値に設定することによって)、 プロパティをCheckedNodes使用して、選択したチェック ボックスを表示するノードを決定します。 このコレクションは、ツリー内で選択されたチェック ボックスを持つすべてのノードを反復処理するために一般的に使用されます。

イベントはTreeNodeCheckChanged、コントロールのチェック ボックスがサーバーへの投稿間でTreeView状態を変更したときに発生します。 これにより、このイベントが発生するたびに、データベースや表示されるコンテンツの更新などのカスタム ルーチンを実行するイベント処理メソッドを提供できます。

注意

コレクションは CheckedNodes 、ツリー構造の深さ優先トラバーサルを使用して設定されます。各親ノードは、次の親ノードが設定される前に、その子ノードまで処理されます。

適用対象

こちらもご覧ください