ノードの深さを取得します。
名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
Public ReadOnly Property Depth As Integer
Dim instance As TreeNode
Dim value As Integer
value = instance.Depth
public int Depth { get; }
public:
property int Depth {
int get ();
}
/** @property */
public int get_Depth ()
public function get Depth () : int
プロパティ値
ノードの深さ。
Depth プロパティを使用して、ノードの深さを確認します。深さは、ノードとルート ノードの間の階層構造のレベル数を表します。たとえば、ルート ノードの深さは 0 です。ルート ノードの子ノードの深さは 1 です。以下同様です。
Depth プロパティを使用して、ノードの深さを確認する方法を次のコード例に示します。深さ 1 のすべてのノードを初期化して、オンの状態にします。この例を正常に動作させるには、以下のサンプル XML データを、Newsgroup.xml という名前のファイルにコピーする必要があります。
<%@ 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 >
<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="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 >
<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>
Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition
Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。
.NET Framework
サポート対象 : 3.0,2.0