TreeNode.Expanded 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
노드가 확장 상태인지 여부를 나타내는 값을 가져오거나 설정합니다.
public:
property Nullable<bool> Expanded { Nullable<bool> get(); void set(Nullable<bool> value); };
public bool? Expanded { get; set; }
member this.Expanded : Nullable<bool> with get, set
Public Property Expanded As Nullable(Of Boolean)
속성 값
노드가 확장되면 true이고, 노드가 확장되지 않으면 false입니다. 또는 null입니다.
예제
다음 코드 예제를 사용 하는 방법에 설명 합니다 Expanded 속성을 프로그래밍 방식으로 노드를 확장 합니다. 모든 노드를 확장 된 상태로 하나는 깊이 사용 하 여 초기화합니다. 루트 노드를 확장 하 고, 해당 자식 노드 확장 되어 있음을 이미 확인 합니다. 이 예제가 제대로 작동 하려면에 대 한 Book.xml 라는 파일에 아래 샘플 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)
{
// Determine the depth of a node as it is bound to data.
// If the depth is 1, expand the node.
if(e.Node.Depth == 1)
{
e.Node.Expanded = true;
}
else
{
e.Node.Expanded = false;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeNode Expanded Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeNode Expanded Example</h3>
<asp:TreeView id="BookTreeView"
DataSourceID="BookXmlDataSource"
OnTreeNodeDataBound="Data_Bound"
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 Data_Bound(ByVal sender As Object, ByVal e As TreeNodeEventArgs)
' Determine the depth of a node as it is bound to data.
' If the depth is 1, expand the node.
If e.Node.Depth = 1 Then
e.Node.Expanded = True
Else
e.Node.Expanded = False
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeNode Expanded Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeNode Expanded Example</h3>
<asp:TreeView id="BookTreeView"
DataSourceID="BookXmlDataSource"
OnTreeNodeDataBound="Data_Bound"
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">
</Section>
<Section Heading="Section 2">
</Section>
</Chapter>
<Chapter Heading="Chapter 2">
<Section Heading="Section 1">
</Section>
</Chapter>
</Book>
설명
사용 된 Expanded 속성을 지정 하거나 노드가 확장 되는지 여부를 확인 합니다.
확장을 호출 하 여 노드를 축소 합니다 Expand 및 Collapse 메서드를 각각. 또한 확장를 호출 하 여 노드와 모든 자식 노드를 축소 합니다 ExpandAll 및 CollapseAll 메서드를 각각.
이후를 Expanded 속성은 세 가지 상태 속성, 다음 C# 코드 조각은 컴파일 오류가 발생 합니다.
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
if (TreeView1.Nodes[0].Expanded)
{
// some work here
}
}
VB.Net 암시적으로 캐스팅 하는 동안 합니다 Boolean 값을 NullableBoolean, C# 하지 않습니다. 따라서 것이 명시적으로 속성의 상태를 확인 하는 것이 좋습니다. 예를 들어, Visual Basic 및 C#에서 다음 코드 예의 값을 명시적으로 테스트를 Expanded 속성입니다.
다음 Visual Basic 코드 예제에서는 값을 명시적으로 테스트를 Expanded 속성입니다. 이 예제에서는 테스트 하는 경우는 Expanded 속성이로 설정 되어 True하므로 Nothing 및 False ('%1!ls!')를 If 문.
If TreeView1.Nodes(0).Expanded = True Then 'some work hereEnd IF
이 C# 코드 예제에서는 값을 명시적으로 테스트를 Expanded 속성입니다. 이 예제에서는 테스트 하는 경우는 Expanded 속성이로 설정 되어 True하므로 Null 및 False ('%1!ls!')를 If 문.
if( TreeView1.Nodes[0].Expanded == true ) { //some work here}