TreeNodeBindingCollection.RemoveAt(Int32) メソッド

定義

指定したインデックス位置にある TreeNodeBinding オブジェクトを TreeNodeBindingCollection オブジェクトから削除します。

public:
 void RemoveAt(int index);
public void RemoveAt (int index);
member this.RemoveAt : int -> unit
Public Sub RemoveAt (index As Integer)

パラメーター

index
Int32

削除する TreeNodeBinding の、0 から始まるインデックス位置。

次のコード例では、メソッドを使用 RemoveAt してオブジェクトからプログラムでオブジェクトを TreeNodeBinding 削除する方法を TreeNodeBindingCollection 示します。 この例を正しく機能させるには、このセクションの最後にある XML データを Book.xml というファイルにコピーする必要があります。


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

    // Use the RemoveAt method to remove the TreeNodeBinding object 
    // for the third-level nodes (index 2).
    BookTreeView.DataBindings.RemoveAt(2);

    // Create a new TreeNodeBinding object and set its properties.
    TreeNodeBinding newBinding = new TreeNodeBinding();
    newBinding.DataMember = "Section";
    newBinding.TextField = "Subject";

    // Use the Insert method to insert the TreeNodeBinding object 
    // into the DaaBindings collection at index 2.
    BookTreeView.DataBindings.Insert(2, newBinding);

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNodeBindingCollection Insert and RemoveAt Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNodeBindingCollection Insert and RemoveAt 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="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 Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        ' Use the RemoveAt method to remove the TreeNodeBinding object
        ' for the third-level nodes (index 2).
        BookTreeView.DataBindings.RemoveAt(2)

        ' Create a new TreeNodeBinding object and set its properties.
        Dim newBinding As TreeNodeBinding = New TreeNodeBinding
        newBinding.DataMember = "Section"
        newBinding.TextField = "Subject"

        ' Use the Insert method to insert the TreeNodeBinding object to
        ' the DataBindings collection at index 2.
        BookTreeView.DataBindings.Insert(2, newBinding)

    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>TreeNodeBindingCollection Insert and RemoveAt Example</title>
</head>
<body>
        <form id="form1" runat="server">
        
            <h3>TreeNodeBindingCollection Insert and RemoveAt 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>

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

<Book Title="Book Title">  
    <Chapter Heading="Chapter 1">  
        <Section Heading="Section 1"  
            Subject="Subject 1">  
        </Section>  
        <Section Heading="Section 2"  
            Subject="Subject 1">  
        </Section>  
    </Chapter>  
    <Chapter Heading="Chapter 2">  
        <Section Heading="Section 1"  
            Subject="Subject 1">  
        </Section>  
    </Chapter>  
</Book>  

注釈

このメソッドをRemoveAt使用して、オブジェクトから位置するTreeNodeBindingindexオブジェクトをTreeNodeBindingCollection削除します。 そのノードに続くすべての項目は、空いている位置を埋めるために上に移動します。 移動された項目のインデックスも更新されます。

別の方法として、メソッドを使用して特定 TreeNodeBinding のオブジェクトを Remove 削除することもできます。 メソッドを使用して、コレクション内のすべてのノードを Clear 削除することもできます。

適用対象

こちらもご覧ください