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 사용하여 개체에서 TreeNodeBinding 있는 index 개체를 TreeNodeBindingCollection 제거합니다. 그런 다음 해당 노드를 따르는 모든 항목이 위로 이동하여 빈 위치를 채웁니다. 이동된 항목의 인덱스도 업데이트됩니다.

또는 메서드를 사용하여 TreeNodeBinding 특정 Remove 개체를 제거할 수 있습니다. 메서드를 사용하여 Clear 컬렉션의 모든 노드를 제거할 수도 있습니다.

적용 대상

추가 정보