Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
12004
How to hide a node in the tree at any level.
posted

How to hide a node in the tree at any level.

Parents
No Data
Reply
  • 12004
    posted

    You can setup the tree for example that will display 2 levels.



    <ig:WebDataTree ID="WebDataTree1" runat="server"
        Height="300px" Width="200px">
        <Nodes>
            <ig:DataTreeNode Text="Root Node 1">
                <Nodes>
                    <ig:DataTreeNode Text="Child Node">
                    </ig:DataTreeNode>
                    <ig:DataTreeNode Text="Child Node">
                    </ig:DataTreeNode>
                </Nodes>
            </ig:DataTreeNode>
            <ig:DataTreeNode Text="Root Node 2">
                <Nodes>
                    <ig:DataTreeNode Text="Child Node">
                    </ig:DataTreeNode>
                    <ig:DataTreeNode Text="Child Node">
                    </ig:DataTreeNode>
                    <ig:DataTreeNode Text="Child Node">
                    </ig:DataTreeNode>
                </Nodes>
            </ig:DataTreeNode>
            <ig:DataTreeNode Text="Root Node 3">
                <Nodes>
                    <ig:DataTreeNode Key="44" Text="Child Node 44">
                    </ig:DataTreeNode>
                    <ig:DataTreeNode Text="Child Node">
                    </ig:DataTreeNode>
                </Nodes>
            </ig:DataTreeNode>
        </Nodes>
    </ig:WebDataTree>



    Under "Root Node 3" contains a child node with the key "44". To walk through every level of the tree you can create a recursive function.



    Public Sub FindNodeByKey(ByRef findNode As DataTreeNode, ByVal node As DataTreeNode, ByVal key As String)
        For Each childNode As DataTreeNode In node.Nodes
            If childNode.Key = key Then
                findNode = childNode
            End If
            For Each nextChildNode As DataTreeNode In childNode.Nodes
                If nextChildNode.Key = key Then
                    findNode = nextChildNode
                End If
                FindNodeByKey(findNode, nextChildNode, key)
            Next
        Next
    End Sub



    Within the recursive function will call the FindNodeByKey() method to walk through the next level if there are any child nodes.

    At the beginning you can loop through the root nodes and then call FindNodeByKey() to walk through every child level.



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim findNode As DataTreeNode = Nothing
        For Each node As DataTreeNode In WebDataTree1.Nodes
            Dim key As String = "44"
            If node.Key = key Then
                findNode = node
            End If
            FindNodeByKey(findNode, node, key)
        Next
        If Not IsNothing(findNode) Then
            findNode.Visible = False
        End If
    End Sub



    In the sample if there's a node (either root or child) that contains the key "44" then it will be hidden in the tree.

    WebDataTree_ParentChild_VB.zip
Children
No Data