IHierarchyData.HasChildren プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > IHierarchyData.HasChildren プロパティの意味・解説 

IHierarchyData.HasChildren プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

IHierarchyData オブジェクトが表す階層データ ノードに子ノードがあるかどうかを示します。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Dim instance As IHierarchyData
Dim value As Boolean

value = instance.HasChildren
bool HasChildren { get; }
property bool HasChildren {
    bool get ();
}
/** @property */
boolean get_HasChildren ()
function get HasChildren () : boolean

プロパティ値
現在のノードが子ノードを持っている場合は true。それ以外の場合は false。

解説解説

HasChildren プロパティを使用すると、呼び出し元で GetChildren メソッドの戻り値が null 参照 (Visual Basic では Nothing) でないかどうかをチェックしなくてすむため、便利です。HasChildren プロパティが true を返せば、GetChildren メソッドを呼び出して子ノードの IHierarchicalEnumerable コレクションを取得できます。

使用例使用例

次のコード例では、階層構造の ASP.NET データ バインド コントロールが、再帰的なデータ バインディング メソッドで IHierarchyData オブジェクトを使用する方法を示します。IHierarchicalEnumerable コレクション内の項目が列挙され、それぞれの項目に対して、GetHierarchyData メソッドを使用して IHierarchyData オブジェクトが取得されます。最後に HasChildren プロパティがチェックされ、再帰が必要かどうかが決定されます。このコード例は、HierarchicalDataBoundControl クラスのトピックで取り上げているコード例の一部分です。

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 'RecurseDataBindInternal

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;
            
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
IHierarchyData インターフェイス
IHierarchyData メンバ
System.Web.UI 名前空間
GetChildren



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「IHierarchyData.HasChildren プロパティ」の関連用語

IHierarchyData.HasChildren プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



IHierarchyData.HasChildren プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS