TreeNodeBindingCollectionとは? わかりやすく解説

TreeNodeBindingCollection クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

TreeView コントロール内の TreeNodeBinding オブジェクトのコレクションを表します。このクラスは継承できません。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public NotInheritable Class
 TreeNodeBindingCollection
    Inherits StateManagedCollection
Dim instance As TreeNodeBindingCollection
public sealed class TreeNodeBindingCollection
 : StateManagedCollection
public ref class TreeNodeBindingCollection
 sealed : public StateManagedCollection
public final class TreeNodeBindingCollection
 extends StateManagedCollection
public final class TreeNodeBindingCollection
 extends StateManagedCollection
解説解説

TreeNodeBindingCollection クラスは、TreeView コントロールに存在する TreeNodeBinding オブジェクトのコレクションを格納および管理する場合に使用されます。TreeView コントロールは、その DataBindings プロパティに TreeNodeBindingCollection クラスを使用します。

DataBindings プロパティには、データ項目とそのバインド先のノードとの間の関係を定義する TreeNodeBinding オブジェクトが含まれています。複数の属性を持つ XML 要素などのように、各データ項目に複数のプロパティが含まれているデータ ソースにバインドする場合、ノードにはデータ項目の ToString メソッドから返される値が既定で表示されます。XML 要素の場合、ノードには要素名が表示されます。これはメニュー ツリーの基になる構造体を示す以外はあまり用途はありません。ツリー ノードのバインディングを指定することにより、ノードを特定のデータ項目のプロパティにバインドできます。DataBindings コレクションはプログラムにより設定できますが、通常は宣言によって設定されます。

ツリー ノード バインディングを宣言して設定するには、次のように操作します。

  1. TreeView コントロールの開始タグと終了タグの間で <DataBindings> の開始タグと終了タグを入れ子にします。

  2. 指定するツリー ノード バインディングごとに、<DataBindings> の開始タグと終了タグの間に <asp:TreeNodeBinding> 要素を入れます。

TreeNodeBinding オブジェクトを追加および削除することにより、TreeNodeBindingCollection オブジェクトをプログラムによって管理できます。TreeNodeBinding オブジェクトをコレクションに追加するには、Add メソッドまたは Insert メソッドを使用します。コレクションからノードを削除するには、Remove、RemoveAt、または StateManagedCollection.Clear の各メソッドを使用します。

TreeNodeBindingCollection クラスは、コレクション内の項目にアクセスするための複数の方法をサポートしています。

使用例使用例

このセクションには、2 つのコード例が含まれています。最初のコード例では、宣言によって TreeNodeBindingCollection オブジェクトに値を代入する方法を示します。2 番目のコード例では、プログラムによって TreeNodeBindingCollection オブジェクトに値を代入する方法を示します。

宣言によって TreeNodeBindingCollection オブジェクトに値を代入するコード例を次に示します。この例を正しく実行するには、このセクションの末尾にある XML データを Book.xml ファイルにコピーする必要があります。

<%@ Page Language="VB" %>

<html>
  <body>
    <form runat="server">
    
      <h3>TreeView XML Data Binding Example</h3>
    
      <asp:TreeView id="BookTreeView" 
        DataSourceID=BookXmlDataSource
        runat="server">
         
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book"
 TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter"
 TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Section"
 TextField="Heading"/>
        </DataBindings>
         
      </asp:TreeView>

      <asp:XmlDataSource id="BookXmlDataSource"
  
        DataFile="Book.xml"
        runat="server">
      </asp:XmlDataSource>
    
    </form>
  </body>
</html>

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

<html>
  <body>
    <form runat="server">
    
      <h3>TreeView XML Data Binding Example</h3>
    
      <asp:TreeView id="BookTreeView" 
        DataSourceID=BookXmlDataSource
        runat="server">
         
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Section" TextField="Heading"/>
        </DataBindings>
         
      </asp:TreeView>

      <asp:XmlDataSource id="BookXmlDataSource"  
        DataFile="Book.xml"
        runat="server">
      </asp:XmlDataSource>
    
    </form>
  </body>
</html>

プログラムによって TreeNodeBindingCollection オブジェクトに値を代入するコード例を次に示します。この例を正しく実行するには、このセクションの末尾にあるサンプル XML データを Book.xml ファイルにコピーする必要があります。

<%@ Page Language="VB" %>

<script runat="server">

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

    ' Create a new TreeView control.
    Dim NewTree As New TreeView

    ' Set the properties of the TreeView control.
    NewTree.ID = "BookTreeView"
    NewTree.DataSourceID = "BookXmlDataSource"

    ' Create the tree node binding relationship.

    ' Create the root node binding.
    Dim RootBinding As New
 TreeNodeBinding
    RootBinding.DataMember = "Book"
    RootBinding.TextField = "Title"

    ' Create the parent node binding.
    Dim ParentBinding As New
 TreeNodeBinding
    ParentBinding.DataMember = "Chapter"
    ParentBinding.TextField = "Heading"

    ' Create the leaf node binding.
    Dim LeafBinding As New
 TreeNodeBinding
    LeafBinding.DataMember = "Section"
    LeafBinding.TextField = "Heading"

    ' Add bindings to the DataBindings collection.
    NewTree.DataBindings.Add(RootBinding)
    NewTree.DataBindings.Add(ParentBinding)
    NewTree.DataBindings.Add(LeafBinding)

    ' Manually register the event handler for the SelectedNodeChanged
 event.
    AddHandler NewTree.SelectedNodeChanged, AddressOf
 Node_Change

    ' Add the TreeView control to the Controls collection of the PlaceHolder
 control.
    ControlPlaceHolder.Controls.Add(NewTree)

  End Sub

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

    ' Retrieve the TreeView control from the Controls collection of
 the PlaceHolder control.
    Dim LocalTree As TreeView = CType(ControlPlaceHolder.FindControl("BookTreeView"),
 TreeView)

    ' Display the selected node.
    Message.Text = "You selected: " & LocalTree.SelectedNode.Text

  End Sub

</script>

<html>
  <body>
    <form runat="server">
    
      <h3>TreeView Constructor Example</h3>
      
      <asp:PlaceHolder id="ControlPlaceHolder"
 runat="server">
      </asp:PlaceHolder>
   
      <asp:XmlDataSource id="BookXmlDataSource"
  
        DataFile="Book.xml"
        runat="server">
      </asp:XmlDataSource>
      
      <br><br>
      
      <asp:Label id="Message" runat="server"/>
    
    </form>
  </body>
</html>

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

<script runat="server">

  void Page_Load(Object sender, EventArgs e)
  {

    // Create a new TreeView control.
    TreeView NewTree = new TreeView();

    // Set the properties of the TreeView control.
    NewTree.ID = "BookTreeView";
    NewTree.DataSourceID = "BookXmlDataSource";

    // Create the tree node binding relationship.

    // Create the root node binding.
    TreeNodeBinding RootBinding = new TreeNodeBinding();
    RootBinding.DataMember = "Book";
    RootBinding.TextField = "Title";

    // Create the parent node binding.
    TreeNodeBinding ParentBinding = new TreeNodeBinding();
    ParentBinding.DataMember = "Chapter";
    ParentBinding.TextField = "Heading";

    // Create the leaf node binding.
    TreeNodeBinding LeafBinding = new TreeNodeBinding();
    LeafBinding.DataMember = "Section";
    LeafBinding.TextField = "Heading";

    // Add bindings to the DataBindings collection.
    NewTree.DataBindings.Add(RootBinding);
    NewTree.DataBindings.Add(ParentBinding); 
    NewTree.DataBindings.Add(LeafBinding);

    // Manually register the event handler for the SelectedNodeChanged
 event.
    NewTree.SelectedNodeChanged += new EventHandler(this.Node_Change);

    // Add the TreeView control to the Controls collection of the PlaceHolder
 control.
    ControlPlaceHolder.Controls.Add(NewTree);

  }

  void Node_Change(Object sender, EventArgs e)
  {

    // Retrieve the TreeView control from the Controls collection of
 the PlaceHolder control.
    TreeView LocalTree = (TreeView)ControlPlaceHolder.FindControl("BookTreeView");

    // Display the selected node.
    Message.Text = "You selected: " + LocalTree.SelectedNode.Text;

  }

</script>

<html>
  <body>
    <form runat="server">
    
      <h3>TreeView Constructor Example</h3>
      
      <asp:PlaceHolder id="ControlPlaceHolder" runat="server">
      </asp:PlaceHolder>
   
      <asp:XmlDataSource id="BookXmlDataSource"  
        DataFile="Book.xml"
        runat="server">
      </asp:XmlDataSource>
      
      <br><br>
      
      <asp:Label id="Message" runat="server"/>
    
    </form>
  </body>
</html>

前のコード例に使用する XML データを次に示します。

<Book Title="Book Title">
    <Chapter Heading="Chapter 1">
       <Section Heading="Section 1">
       </Section>
       <Section Heading="Section 2">
       </Section>
    </Chapter>
    <Chapter Heading="Chapter 2">
        <Section Heading="Section 1">
        </Section>
    </Chapter>
</Book>
継承階層継承階層
System.Object
   System.Web.UI.StateManagedCollection
    System.Web.UI.WebControls.TreeNodeBindingCollection
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TreeNodeBindingCollection メンバ
System.Web.UI.WebControls 名前空間
TreeView
TreeNode クラス
TreeNodeBinding クラス
DataBindings
Add
Insert
Remove
RemoveAt
StateManagedCollection.Clear

TreeNodeBindingCollection プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Count  StateManagedCollection コレクションに格納されている要素の数を取得します。 ( StateManagedCollection から継承されます。)
パブリック プロパティ Item TreeNodeBindingCollection オブジェクト内の指定したインデックス位置にある TreeNodeBinding オブジェクトを取得または設定します。
参照参照

関連項目

TreeNodeBindingCollection クラス
System.Web.UI.WebControls 名前空間
TreeView
TreeNode クラス
TreeNodeBinding クラス
DataBindings
Add
Insert
Remove
RemoveAt
StateManagedCollection.Clear

TreeNodeBindingCollection メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Add 指定した TreeNodeBinding オブジェクトを TreeNodeBindingCollection オブジェクトの末尾に追加します。
パブリック メソッド Clear  StateManagedCollection コレクションからすべての項目を削除します。 ( StateManagedCollection から継承されます。)
パブリック メソッド Contains 指定した TreeNodeBinding オブジェクトがコレクション内にあるかどうかを確認します。
パブリック メソッド CopyTo オーバーロードされます。 TreeNodeBindingCollection オブジェクトからすべての項目をコピーします。
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。)
パブリック メソッド GetEnumerator  StateManagedCollection コレクションを反復処理する反復子を返します。 ( StateManagedCollection から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド IndexOf コレクション内の指定した TreeNodeBinding オブジェクトのインデックスを確認します。
パブリック メソッド Insert 指定した TreeNodeBinding オブジェクトを TreeNodeBindingCollection オブジェクトの指定したインデックス位置に挿入します。
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド Remove 指定した TreeNodeBinding オブジェクトを TreeNodeBindingCollection オブジェクトから削除します。
パブリック メソッド RemoveAt 指定したインデックス位置にある TreeNodeBinding オブジェクトを TreeNodeBindingCollection オブジェクトから削除します。
パブリック メソッド SetDirty  強制的に StateManagedCollection コレクション全体をビューステートにシリアル化します。 ( StateManagedCollection から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

TreeNodeBindingCollection クラス
System.Web.UI.WebControls 名前空間
TreeView
TreeNode クラス
TreeNodeBinding クラス
DataBindings
Add
Insert
Remove
RemoveAt
StateManagedCollection.Clear

TreeNodeBindingCollection メンバ

TreeView コントロール内の TreeNodeBinding オブジェクトのコレクションを表します。このクラスは継承できません。

TreeNodeBindingCollection データ型で公開されるメンバを以下の表に示します。


パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Count  StateManagedCollection コレクションに格納されている要素の数を取得します。(StateManagedCollection から継承されます。)
パブリック プロパティ Item TreeNodeBindingCollection オブジェクト内の指定したインデックス位置にある TreeNodeBinding オブジェクトを取得または設定します。
パブリック メソッドパブリック メソッド
( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Add 指定した TreeNodeBinding オブジェクトを TreeNodeBindingCollection オブジェクトの末尾に追加します。
パブリック メソッド Clear  StateManagedCollection コレクションからすべての項目を削除します。 (StateManagedCollection から継承されます。)
パブリック メソッド Contains 指定した TreeNodeBinding オブジェクトがコレクション内にあるかどうかを確認します。
パブリック メソッド CopyTo オーバーロードされます。 TreeNodeBindingCollection オブジェクトからすべての項目をコピーします。
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。)
パブリック メソッド GetEnumerator  StateManagedCollection コレクションを反復処理する反復子を返します。 (StateManagedCollection から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド IndexOf コレクション内の指定した TreeNodeBinding オブジェクトのインデックスを確認します。
パブリック メソッド Insert 指定した TreeNodeBinding オブジェクトを TreeNodeBindingCollection オブジェクトの指定したインデックス位置に挿入します。
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド Remove 指定した TreeNodeBinding オブジェクトを TreeNodeBindingCollection オブジェクトから削除します。
パブリック メソッド RemoveAt 指定したインデックス位置にある TreeNodeBinding オブジェクトを TreeNodeBindingCollection オブジェクトから削除します。
パブリック メソッド SetDirty  強制的に StateManagedCollection コレクション全体をビューステートにシリアル化します。 (StateManagedCollection から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

TreeNodeBindingCollection クラス
System.Web.UI.WebControls 名前空間
TreeView
TreeNode クラス
TreeNodeBinding クラス
DataBindings
Add
Insert
Remove
RemoveAt
StateManagedCollection.Clear



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「TreeNodeBindingCollection」の関連用語

TreeNodeBindingCollectionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TreeNodeBindingCollectionのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS