开发者

How to add a new treeview at the selected node?

I have a treeview with four levels; parent, child, grandchild, great-grandchild. My selectednode is at the grandchild level.

What I'm trying to do is to create a new "Treeview" at the grandchild - NO, I dont wnat to create a new node to the "selectednode" (grandchild). So it should be somelike this:

parent child grandchild (New TreeView) PARENT which was grandchild

great-grandchild child

great-grandchild child grandchild grandchild

It would be similar to a parent table where the mother and father went off and had new childern with a different spouse other than the spouse of there existing children.

   Private Sub PopulateRootLevel()
            ' query to find first round of parent
            PopulateNodes(dt, JCATreeView.No开发者_如何学运维des)
    End Sub

Private Sub PopulateNodes(ByVal dt As DataTable, ByVal nodes As TreeNodeCollection)
        For Each dr As DataRow In dt.Rows
            Dim tn As New TreeNode()
            tn.Text = dr("TITLE").ToString()
            tn.Value = dr("Parent_ID").ToString()
            nodes.Add(tn)

            'If node has child nodes, then enable on-demand populating
            tn.PopulateOnDemand = (CInt(dr("childnodecount")) > 0)
        Next
End Sub

Private Sub PopulateSubLevel(ByVal parentid As Integer, ByVal parentNode As TreeNode)

        ' query to find children of parent with child node count of parent
         da.Fill(dt)
        PopulateNodes(dt, parentNode.ChildNodes)
End Sub

Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, _
  ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate
        ' add a test to determine if this is from TreeView1 or Sub_TreeView1
         PopulateSubLevel(CInt(e.Node.Value), e.Node)
End Sub

Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChanged

        Dim selected_parent_id As Integer = sender.SelectedNode.value
        Parent_to_NEW_TREEVIEW_PopulateSubLevel(selected_parent_id, sender.SelectedNode)
End Sub

Private Sub Sub_TreeView1_PopulateSubLevel(ByVal parent_id As Integer, ByVal parentNode As TreeNode)

        ' Query to get new children of parents
        da.Fill(dt2)
        Sub_TreeView1_PopulateNodes(dt2, parentNode.ChildNodes)
End Sub

    Private Sub Sub_TreeView1_PopulateNodes(ByVal dt As DataTable, ByVal nodes As TreeNodeCollection)
        For Each dr As DataRow In dt.Rows
            Dim tn As TreeNode = New TreeNode()
            'tn = parentBCNode.Nodes.Add("NEW_PARENT_TREEVIEW")

            ' query to get child on the new parent treeview

            tn.Text = dr("New parent title").ToString()
            tn.Value = dr("New_parent_ID").ToString()
            nodes.Add(tn)

            'If node has child nodes, then enable on-demand populating
            tn.PopulateOnDemand = (CInt(dr("childnodecount")) > 0)
        Next
    End Sub


You can't do that. A TreeView can not have as one of its child nodes another TreeView control. The only thing you can do is assign the TreeView to the tag property of a TreeNode, but that will not be displayed (obviously). I don't understand why you would want to do that, unless you want a different drawing behavior for that grand-child sub-tree. You can make use of the treeNode.Level property to find out at which level that node is. And again you can create a custom object(that has all your required information) and store it in the treeNode.Tag property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜