TreeNode.Depth 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
노드의 깊이를 가져옵니다.
public:
property int Depth { int get(); };
[System.ComponentModel.Browsable(false)]
public int Depth { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Depth : int
Public ReadOnly Property Depth As Integer
속성 값
노드의 깊이입니다.
- 특성
예제
다음 코드 예제에서는 노드의 깊이 결정 하는 속성을 사용 Depth 하는 방법을 보여 줍니다. 깊이가 1인 모든 노드를 선택한 상태로 초기화합니다. 이 예제가 제대로 작동하려면 아래 예제 XML 데이터를 Newsgroup.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 Data_Bound(Object sender, TreeNodeEventArgs e)
{
// Check the depth of a node as it is being bound to data.
// Initialize the Checked property to true if the depth is 1.
if(e.Node.Depth == 1)
{
e.Node.Checked = true;
}
else
{
e.Node.Checked = false;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeNode Checked Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeNode Checked Example</h3>
<asp:TreeView id="NewsgroupTreeView"
DataSourceID="NewsgroupXmlDataSource"
OnTreeNodeDataBound="Data_Bound"
ShowCheckBoxes="All"
ExpandDepth="2"
runat="server">
<DataBindings>
<asp:TreeNodeBinding DataMember="category" TextField="Name"/>
<asp:TreeNodeBinding DataMember="group" TextField="Name"/>
</DataBindings>
</asp:TreeView>
<asp:XmlDataSource id="NewsgroupXmlDataSource"
DataFile="Newsgroup.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 Data_Bound(ByVal sender As Object, ByVal e As TreeNodeEventArgs)
' Check the depth of a node as it is being bound to data.
' Initialize the Checked property to true if the depth is 1.
If e.Node.Depth = 1 Then
e.Node.Checked = True
Else
e.Node.Checked = False
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeNode Checked Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeNode Checked Example</h3>
<asp:TreeView id="NewsgroupTreeView"
DataSourceID="NewsgroupXmlDataSource"
OnTreeNodeDataBound="Data_Bound"
ShowCheckBoxes="All"
ExpandDepth="2"
runat="server">
<DataBindings>
<asp:TreeNodeBinding DataMember="category" TextField="Name"/>
<asp:TreeNodeBinding DataMember="group" TextField="Name"/>
</DataBindings>
</asp:TreeView>
<asp:XmlDataSource id="NewsgroupXmlDataSource"
DataFile="Newsgroup.xml"
runat="server">
</asp:XmlDataSource>
</form>
</body>
</html>
다음 코드는 이전 예제의 샘플 XML 데이터입니다.
<category name="news.microsoft.com">
<group name="microsoft.public.dotnet.framework.aspnet"/>
<group name="microsoft.public.dotnet.framework.aspnet.mobile"/>
<group name="microsoft.public.dotnet.framework.aspnet.webservices"/>
</category>
설명
이 Depth 속성을 사용하여 노드의 깊이를 확인합니다. 깊이는 노드와 루트 노드 간의 계층 구조 수준을 나타냅니다. 예를 들어 루트 노드의 깊이는 0입니다. 루트 노드의 자식에는 깊이가 1개 등입니다.