IHierarchyData.HasChildren 속성

정의

IHierarchyData 개체가 나타내는 계층적 데이터 노드에 자식 노드가 있는지 여부를 나타냅니다.

public:
 property bool HasChildren { bool get(); };
public bool HasChildren { get; }
member this.HasChildren : bool
Public ReadOnly Property HasChildren As Boolean

속성 값

Boolean

현재 노드에 자식 노드가 있으면 true이고, 그렇지 않으면 false입니다.

예제

다음 코드 예제에서는 ASP.NET 계층적 데이터 바인딩된 컨트롤을 사용 하는 방법을 보여 줍니다는 IHierarchyData 재귀 데이터 바인딩 메서드에서는 개체입니다. 항목을 IHierarchicalEnumerable 열거 되 고 각 컬렉션은는 IHierarchyData 개체를 사용 하 여 검색 됩니다는 GetHierarchyData 메서드. 마지막으로 HasChildren recurse를 결정 하기 위해 속성을 검사 합니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 HierarchicalDataBoundControl 클래스입니다.

private void RecurseDataBindInternal(TreeNode node, 
    IHierarchicalEnumerable enumerable, int depth) {                                    
                
    foreach(object item in enumerable) {
        IHierarchyData data = enumerable.GetHierarchyData(item);

        if (null != data) {
            // Create an object that represents the bound data
            // to the control.
            TreeNode newNode = new TreeNode();
            RootViewNode rvnode = new RootViewNode();
            
            rvnode.Node = newNode;
            rvnode.Depth = depth;

            // The dataItem is not just a string, but potentially
            // an XML node or some other container. 
            // If DataTextField is set, use it to determine which 
            // field to render. Otherwise, use the first field.                    
            if (DataTextField.Length > 0) {
                newNode.Text = DataBinder.GetPropertyValue
                    (data, DataTextField, null);
            }
            else {
                PropertyDescriptorCollection props = 
                    TypeDescriptor.GetProperties(data);

                // Set the "default" value of the node.
                newNode.Text = String.Empty;                        

                // Set the true data-bound value of the TextBox,
                // if possible.
                if (props.Count >= 1) {                        
                    if (null != props[0].GetValue(data)) {
                        newNode.Text = 
                            props[0].GetValue(data).ToString();
                    } 
                }
            }

            Nodes.Add(rvnode);                    
            
            if (data.HasChildren) {
                IHierarchicalEnumerable newEnumerable = 
                    data.GetChildren();
                if (newEnumerable != null) {                            
                    RecurseDataBindInternal(newNode, 
                        newEnumerable, depth+1 );
                }
            }
            
            if ( _maxDepth < depth) _maxDepth = depth;
        }
    }
}
Private Sub RecurseDataBindInternal(ByVal node As TreeNode, _
    ByVal enumerable As IHierarchicalEnumerable, _
    ByVal depth As Integer)

    Dim item As Object
    For Each item In enumerable

        Dim data As IHierarchyData = enumerable.GetHierarchyData(item)

        If Not data Is Nothing Then

            ' Create an object that represents the bound data
            ' to the control.
            Dim newNode As New TreeNode()
            Dim rvnode As New RootViewNode()

            rvnode.Node = newNode
            rvnode.Depth = depth

            ' The dataItem is not just a string, but potentially
            ' an XML node or some other container. 
            ' If DataTextField is set, use it to determine which 
            ' field to render. Otherwise, use the first field.                    
            If DataTextField.Length > 0 Then
                newNode.Text = DataBinder.GetPropertyValue _
                (data, DataTextField, Nothing)
            Else
                Dim props As PropertyDescriptorCollection = _
                TypeDescriptor.GetProperties(data)

                ' Set the "default" value of the node.
                newNode.Text = String.Empty

                ' Set the true data-bound value of the TextBox,
                ' if possible.
                If props.Count >= 1 Then
                    If Not props(0).GetValue(data) Is Nothing Then
                        newNode.Text = props(0).GetValue(data).ToString()
                    End If
                End If
            End If

            Nodes.Add(rvnode)

            If data.HasChildren Then
                Dim newEnumerable As IHierarchicalEnumerable = _
                    data.GetChildren()
                If Not (newEnumerable Is Nothing) Then
                    RecurseDataBindInternal(newNode, _
                    newEnumerable, depth + 1)
                End If
            End If

            If MaxDepth < depth Then
                MaxDepth = depth
            End If
        End If
    Next item

End Sub

설명

합니다 HasChildren 속성은 호출자의 반환 값을 확인 하지 않으려면 수 있게 해 주는 편의 속성을 GetChildren 에 대 한 메서드 null합니다. 경우는 HasChildren 속성에서 반환 true, 호출를 GetChildren 검색 하는 메서드는 IHierarchicalEnumerable 자식 노드의 컬렉션입니다.

적용 대상

추가 정보