TreeNodeCollection 클래스

정의

TreeView 컨트롤에 있는 TreeNode 개체의 컬렉션을 나타냅니다. 이 클래스는 상속될 수 없습니다.

public ref class TreeNodeCollection sealed : System::Collections::ICollection, System::Web::UI::IStateManager
public sealed class TreeNodeCollection : System.Collections.ICollection, System.Web.UI.IStateManager
type TreeNodeCollection = class
    interface ICollection
    interface IEnumerable
    interface IStateManager
Public NotInheritable Class TreeNodeCollection
Implements ICollection, IStateManager
상속
TreeNodeCollection
구현

예제

다음 예제에서는 프로그래밍 방식으로 노드를 추가 하 고 제거 하는 방법을 보여 줍니다는 TreeNodeCollection합니다. 다음에 유의 합니다 NodesChildNodes 속성 반환을 TreeNodeCollection 개체.


<%@ 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)
  {

    if (!IsPostBack)
    {

      // Use the Add and Remove methods to programmatically 
      // remove the Appendix C node and replace it with a new 
      // node. 
      LinksTreeView.Nodes.Remove(LinksTreeView.Nodes[3]);
      LinksTreeView.Nodes.Add(new TreeNode("New Appendix C"));

      // Use the AddAt and RemoveAt methods to programmatically 
      // remove the Chapter One node and replace it with a new node.
      LinksTreeView.Nodes[0].ChildNodes.RemoveAt(0);
      LinksTreeView.Nodes[0].ChildNodes.AddAt(0, new TreeNode("New Chapter One"));

      // Use the Clear method to remove all the child nodes of the 
      // Chapter Two node.
      LinksTreeView.Nodes[0].ChildNodes[1].ChildNodes.Clear();

    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNodeCollection Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNodeCollection Example</h3>
    
      <asp:TreeView id="LinksTreeView"
        Font-Names= "Arial"
        ForeColor="Blue"
        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"
            Expanded="true">
             
            <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>

    </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)

    If Not IsPostBack Then

      ' Use the Add and Remove methods to programmatically 
      ' remove the Appendix C node and replace it with a new 
      ' node. 
      LinksTreeView.Nodes.Remove(LinksTreeView.Nodes(3))
      LinksTreeView.Nodes.Add(New TreeNode("New Appendix C"))

      ' Use the AddAt and RemoveAt methods to programmatically 
      ' remove the Chapter One node and replace it with a new node.
      LinksTreeView.Nodes(0).ChildNodes.RemoveAt(0)
      LinksTreeView.Nodes(0).ChildNodes.AddAt(0, New TreeNode("New Chapter One"))

      ' Use the Clear method to remove all the child nodes of the 
      ' Chapter Two node.
      LinksTreeView.Nodes(0).ChildNodes(1).ChildNodes.Clear()

    End If

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNodeCollection Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNodeCollection Example</h3>
    
      <asp:TreeView id="LinksTreeView"
        Font-Names= "Arial"
        ForeColor="Blue"
        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"
            Expanded="true">
             
            <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>

    </form>
  </body>
</html>

설명

합니다 TreeNodeCollection 클래스 저장 하 고 컬렉션을 관리 하는 데 사용 됩니다 TreeNode 개체는 TreeView 제어 합니다. TreeView 컨트롤이 사용 하는 TreeNodeCollection 두 가지 속성에는 클래스입니다. 해당 루트 노드를 저장 합니다 Nodes 속성과에서 선택 된 노드는 CheckedNodes 속성입니다. 합니다 TreeNodeCollection 컬렉션에도 사용 됩니다는 ChildNodes (있는 경우)에 자식 노드를 저장 하는 속성입니다.

TreeNodeCollection 클래스는 컬렉션의 항목에 액세스 하는 여러 방법을 지원 합니다.

  • 사용 된 Item[] 검색할 인덱서의 TreeNode 특정 인덱스에서 직접 개체입니다.

  • 사용 된 GetEnumerator 컬렉션을 반복 하는 데 사용할 수 있는 열거자를 만드는 방법.

  • 사용 하 여 foreach (C#) 또는 For Each (Visual Basic)의 컬렉션을 반복 합니다.

  • 사용 합니다 CopyTo 컬렉션의 내용을 복사 하는 메서드는 Array 개체입니다.

프로그래밍 방식으로 관리할 수 있습니다 합니다 TreeNodeCollection 추가 및 제거 하 여 TreeNode 개체입니다. 컬렉션에 노드를 추가 하려면 사용 합니다 Add 또는 AddAt 메서드. 컬렉션에서 노드를 제거 하려면 사용 합니다 Remove, RemoveAt, 또는 Clear 메서드.

참고

경우는 TreeView 컨트롤이 데이터 소스에 바인딩되는 NodesChildNodes 컬렉션은 바인딩이 발생할 때마다 자동으로 채워집니다. 바인딩 간의 컬렉션에 모든 변경 내용이 손실 됩니다. 이러한 변경 내용을 유지 하려면 데이터 원본을 업데이트 하거나 수동으로 바인딩할 때마다 컬렉션을 다시 합니다.

TreeNodeCollection 컬렉션 자체에 대 한 정보를 검색할 수 있는 메서드와 속성을 포함 합니다. 컬렉션에 있는 항목 수를 확인 하려면 사용 된 Count 속성입니다. 특정 컬렉션에 있는지 여부를 확인 하려는 경우 TreeNode 개체는 Contains 메서드. 인덱스를 가져올는 TreeNode 사용 하 여 컬렉션에서 개체를 IndexOf 메서드.

생성자

TreeNodeCollection()

기본값을 사용하여 TreeNodeCollection 클래스의 새 인스턴스를 초기화합니다.

TreeNodeCollection(TreeNode)

지정된 부모 노드(또는 소유자)를 사용하여 TreeNodeCollection 클래스의 새 인스턴스를 초기화합니다.

속성

Count

TreeNodeCollection 개체의 항목 수를 가져옵니다.

IsSynchronized

TreeNodeCollection에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지를 나타내는 값을 가져옵니다.

Item[Int32]

TreeNode 개체의 지정된 인덱스에 있는 TreeNodeCollection 개체를 가져옵니다.

SyncRoot

TreeNodeCollection 개체에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

메서드

Add(TreeNode)

지정된 TreeNode 개체를 TreeNodeCollection 개체의 끝에 추가합니다.

AddAt(Int32, TreeNode)

지정된 TreeNode 개체를 TreeNodeCollection 개체의 지정된 인덱스 위치에 삽입합니다.

Clear()

TreeNodeCollection 개체를 비웁니다.

Contains(TreeNode)

지정된 TreeNode 개체가 컬렉션에 있는지 여부를 확인합니다.

CopyTo(TreeNode[], Int32)

대상 배열의 지정한 인덱스부터 시작하여 TreeNodeCollection 개체의 모든 항목을 TreeNode 개체의 호환되는 1차원 배열에 복사합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetEnumerator()

TreeNodeCollection 개체를 반복하는 데 사용할 수 있는 열거자를 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IndexOf(TreeNode)

지정된 TreeNode 개체의 인덱스를 확인합니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Remove(TreeNode)

TreeNode 개체에서 지정한 TreeNodeCollection 개체를 제거합니다.

RemoveAt(Int32)

TreeNode 개체에서 지정한 인덱스에 있는 TreeNodeCollection 개체를 제거합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ICollection.CopyTo(Array, Int32)

대상 배열의 지정한 인덱스부터 시작하여 TreeNodeCollection 개체의 모든 항목을 호환되는 1차원 Array에 복사합니다.

IStateManager.IsTrackingViewState

TreeNodeCollection 개체가 해당 뷰 상태의 변경 내용을 저장하는지 여부를 나타내는 값을 가져옵니다.

IStateManager.LoadViewState(Object)

이전에 저장된 TreeNodeCollection 개체의 뷰 상태를 로드합니다.

IStateManager.SaveViewState()

Object에 뷰 상태 변경 내용을 저장합니다.

IStateManager.TrackViewState()

TreeNodeCollection에서 해당 뷰 상태의 변경 내용을 추적하도록 합니다.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상

추가 정보