IHierarchicalEnumerable.GetHierarchyData(Object) 메서드

정의

지정된 열거형 항목에 대한 계층적 데이터 항목을 반환합니다.Returns a hierarchical data item for the specified enumerated item.

public:
 System::Web::UI::IHierarchyData ^ GetHierarchyData(System::Object ^ enumeratedItem);
public System.Web.UI.IHierarchyData GetHierarchyData (object enumeratedItem);
abstract member GetHierarchyData : obj -> System.Web.UI.IHierarchyData
Public Function GetHierarchyData (enumeratedItem As Object) As IHierarchyData

매개 변수

enumeratedItem
Object

Object를 반환할 IHierarchyData입니다.The Object for which to return an IHierarchyData.

반환

IHierarchyData 메서드에 전달된 Object를 나타내는 GetHierarchyData(Object) 인스턴스입니다.An IHierarchyData instance that represents the Object passed to the GetHierarchyData(Object) method.

예제

다음 코드 예제에서는 ASP.NET 계층적 데이터 바인딩된 컨트롤을 사용 하는 방법을 보여 줍니다는 IHierarchyData 재귀 데이터 바인딩 메서드에서는 개체입니다.The following code example demonstrates how an ASP.NET hierarchical data-bound control uses an IHierarchyData object in a recursive data-binding method. 항목을 IHierarchicalEnumerable 열거 되 고 각 개체는는 IHierarchyData 개체를 사용 하 여 검색 됩니다는 GetHierarchyData 메서드.The items in an IHierarchicalEnumerable object are enumerated, and for each an IHierarchyData object is retrieved using the GetHierarchyData method. 마지막으로 HasChildren 재귀 필요한 되는지 확인 하려면 속성을 검사 합니다.Finally, the HasChildren property is checked to determine whether recursion is necessary. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 HierarchicalDataBoundControl 클래스입니다.This code example is part of a larger example provided for the HierarchicalDataBoundControl class.

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

설명

일반적으로 사용 하는 클라이언트 IHierarchicalEnumerable 컬렉션 검색를 IEnumerator 를 호출 하 여 개체를 GetEnumerator 메서드를 다음 열거형 및 호출을 반복 합니다 GetHierarchyData 검색할 열거 된 각 항목에 대 한 메서드는 IHierarchyData 개체입니다.Typically, clients that use IHierarchicalEnumerable collections retrieve an IEnumerator object by calling the GetEnumerator method, then iterate through the enumeration and call the GetHierarchyData method on each enumerated item to retrieve an IHierarchyData object.

적용 대상

추가 정보