TreeNodeBindingCollection クラス
アセンブリ: System.Web (system.web.dll 内)
構文
解説TreeNodeBindingCollection クラスは、TreeView コントロールに存在する TreeNodeBinding オブジェクトのコレクションを格納および管理する場合に使用されます。TreeView コントロールは、その DataBindings プロパティに TreeNodeBindingCollection クラスを使用します。
DataBindings プロパティには、データ項目とそのバインド先のノードとの間の関係を定義する TreeNodeBinding オブジェクトが含まれています。複数の属性を持つ XML 要素などのように、各データ項目に複数のプロパティが含まれているデータ ソースにバインドする場合、ノードにはデータ項目の ToString メソッドから返される値が既定で表示されます。XML 要素の場合、ノードには要素名が表示されます。これはメニュー ツリーの基になる構造体を示す以外はあまり用途はありません。ツリー ノードのバインディングを指定することにより、ノードを特定のデータ項目のプロパティにバインドできます。DataBindings コレクションはプログラムにより設定できますが、通常は宣言によって設定されます。
ツリー ノード バインディングを宣言して設定するには、次のように操作します。
-
TreeView コントロールの開始タグと終了タグの間で <DataBindings> の開始タグと終了タグを入れ子にします。
-
指定するツリー ノード バインディングごとに、<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>
継承階層System.Web.UI.StateManagedCollection
System.Web.UI.WebControls.TreeNodeBindingCollection
スレッド セーフ
プラットフォームWindows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照TreeNodeBindingCollection プロパティ
パブリック プロパティ| 名前 | 説明 | |
|---|---|---|
| Count | StateManagedCollection コレクションに格納されている要素の数を取得します。 ( StateManagedCollection から継承されます。) |
| Item | TreeNodeBindingCollection オブジェクト内の指定したインデックス位置にある TreeNodeBinding オブジェクトを取得または設定します。 |
参照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 から継承されます。) |
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |
参照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 から継承されます。) |
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |
参照Weblioに収録されているすべての辞書からTreeNodeBindingCollectionを検索する場合は、下記のリンクをクリックしてください。
全ての辞書からTreeNodeBindingCollection
を検索
- TreeNodeBindingCollectionのページへのリンク